-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathStrings.applescript
More file actions
69 lines (59 loc) · 2.01 KB
/
Copy pathStrings.applescript
File metadata and controls
69 lines (59 loc) · 2.01 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
(*
Strings Library
v1.0
Dov Frankel, 2013
property LibLoader : load script file ((path to scripts folder from user domain as text) & "Libraries:Library Loader.scpt")
property StringsLib : LibLoader's loadScript("Libraries:Strings.applescript")
*)
-- Quantity is the count of items, >= 0 (e.g. 5)
-- Singular is the subject's singular (e.g. "query")
-- Plural is the subject's plural (e.g. "queries")
(*
StringsLib's Pluralize(1000, "query", "queries")
*)
on Pluralize(Quantity, Singular, Plural)
set subject to Plural
if Quantity = 1 then set subject to Singular
set message to (Quantity as text) & " " & subject
return message
end Pluralize
-- Trims spaces from beginning and end of someText
(*
StringsLib's Trim(" spaced text ")
*)
on trim(someText)
set theseCharacters to Â
{" ", tab, ASCII character 10, return, ASCII character 0}
--log "Trimming text: " & someText
repeat until first character of someText is not in theseCharacters
set someText to text 2 thru -1 of someText
end repeat
repeat until last character of someText is not in theseCharacters
set someText to text 1 thru -2 of someText
end repeat
return someText
end trim
-- Splits out the string into its component parts
(*
StringsLib's Split(":", "a:b:c")
*)
on split(delimiter, someText)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to delimiter
set output to text items of (someText as string)
set AppleScript's text item delimiters to prevTIDs
return output
end split
-- Replaces a substring with another substring
(*
set my_var to StringsLib's replace_text(some_text, "abc", "def")
*)
on replace_text(this_text, search_string, replacement_string)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to prevTIDs
return this_text
end replace_text