Last active
April 18, 2022 01:48
-
-
Save Teraflopst/fd9087b50f8d95697807c6a222dcecd7 to your computer and use it in GitHub Desktop.
AppleScript: get filename and extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 theFullFileName to name of file pFile | |
-- Get filename "Safari.app" with extension | |
tell application "Finder" to set theFileExtension to name extension of file pFile | |
-- Get extension "app" | |
set xtsLength to count of theFileExtension | |
-- Get extension "app" length: 3 | |
set theFileName to text 1 thru -(xtsLength + 2) of theFileName | |
-- Get filename "Safari" without extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Description: | |
-- Get filepath, filename and extension of selected file | |
tell application "Finder" to set theFilePath to POSIX path of (selection as alias) | |
-- "/Applications/Safari.app" | |
tell application "Finder" to set theFullFileName to name of (selection as alias) | |
-- "Safari.app" | |
tell application "Finder" to set theFileExtension to name extension of (selection as alias) | |
-- "app" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment