-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_clipboard.applescript
More file actions
81 lines (69 loc) · 2.54 KB
/
parse_clipboard.applescript
File metadata and controls
81 lines (69 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
on run argv
set theQuery to item 1 of argv
set textItemList to splitString(theQuery)
if textItemList is {} then
return
end if
set skipPrefix to (system attribute "skip_prefix")
set firstOk to false
repeat while not firstOk and textItemList is not {}
set firstTextItem to trimWhitespace(first item of textItemList)
set restTextItems to the rest of textItemList
set textItemList to restTextItems
set firstOk to (firstTextItem does not start with skipPrefix)
end repeat
set the clipboard to trimWhitespace(joinToString(restTextItems))
if firstOk then
set bundleID to (system attribute "alfred_workflow_bundleid")
tell application id "com.runningwithcrayons.Alfred"
run trigger "singleItemPaste" in workflow bundleID with argument firstTextItem
end tell
end if
end run
on splitString(thisString)
set previousDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to getDelimiter()
set textItemList to text items of thisString
set AppleScript's text item delimiters to previousDelimiters
return textItemList
end splitString
on joinToString(thisList)
set previousDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to getDelimiter()
set joinedString to thisList as text
set AppleScript's text item delimiters to previousDelimiters
return joinedString
end joinToString
on getDelimiter()
set prefD to (system attribute "delimiter")
return {linefeed & prefD & linefeed, return & prefD & return, return & prefD & return, character id 8233 & prefD & character id 8233, character id 8233 & prefD & character id 8233}
end getDelimiter
on trimWhitespace(this_text)
return trimString(this_text, return & linefeed & character id 8233 & character id 8232 & " ", 2)
end trimWhitespace
on trimString(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while the length of this_text > 0 and trim_chars contains character 1 of this_text
try
set this_text to characters 2 thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while the length of this_text > 0 and trim_chars contains character -1 of this_text
try
set this_text to characters 1 thru -2 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trimString