-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathFilenames.applescript
More file actions
43 lines (31 loc) · 1.23 KB
/
Copy pathFilenames.applescript
File metadata and controls
43 lines (31 loc) · 1.23 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
(*
Filenames 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 FilenamesLib : LibLoader's loadScript("Libraries:Filenames.applescript")
*)
-- Returns the extension of a file (of a URL or POSIX path)
on GetExtension(FilePath)
try
set oldDelims to AppleScript's text item delimiters -- save their current state
set AppleScript's text item delimiters to {"."}
set theExtension to last text item of FilePath
return theExtension
on error errMessage
set AppleScript's text item delimiters to oldDelims -- restore them if something went wrong
log "Filenames:GetExtension(FilePath) failed: " & errMessage
end try
end GetExtension
-- Returns the name of a file (of a URL or POSIX path)
on GetFileName(FilePath)
try
set oldDelims to AppleScript's text item delimiters -- save their current state
set AppleScript's text item delimiters to {"/"}
set theFileName to last text item of FilePath
return theFileName
on error errMessage
set AppleScript's text item delimiters to oldDelims -- restore them if something went wrong
log "Filenames:GetFileName(FilePath) failed: " & errMessage
end try
end GetFileName