Teraflopst
8/23/2016 - 4:23 AM

AppleScript: get filename and extension

AppleScript: get filename and extension

-- Description
-- Get filename or extension of POSIX path

set p to "/Applications/Safari.app"
set pFile to POSIX file p
tell application "Finder" to set pathName to name of file pFile --Get filename "Safari.app" with extension
tell application "Finder" to set fileExtension to name extension of file pFile --Get extension "app"
set xtsLength to count of fileExtension --Get extension "app" length: 3
set appName to text 1 thru -(xtsLength + 2) of pathName --Get filename "Safari" without extension
-- Description:
-- Get filename and extension of selected file

tell application "Finder" to set theFile to POSIX path of (selection as alias)
tell application "Finder" to set fileExtension to name extension of (selection as alias)