Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created May 28, 2020 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingsai/c23bef2caea8c4a7ca864612b1adea8c to your computer and use it in GitHub Desktop.
Save mingsai/c23bef2caea8c4a7ca864612b1adea8c to your computer and use it in GitHub Desktop.
Applescript: Trim text front and back example
set whichFile to choose file with multiple selections allowed
repeat with aFile in whichFile
tell application "Finder"
set filename to name of aFile
set name of aFile to ((characters 4 thru -1 of filename) as string) --trim first 3
--set name of whichFile to ((characters 1 thru -4 of filename) as string) --trim last 3
end tell
end repeat
@AtomicNess123
Copy link

How would you add a string at the end of the name and before the extension?

set name of aFile to ((characters 4 thru -1 of filename) & "text" as string)

However, this adds the "text" string after the extension. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment