Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Renaming a file using AppleScript

The following AppleScript function renames a file. If you thought this to be a simple thing, try to write it without looking here below. I spend a lot time on this, I might not even use it, but here it is for other mortals wishing to lose weight exercising AppleScript:

to renameFile(oldAlias, newFileName)
 tell application "Finder"
  set f to item (oldAlias as text)
  tell f
   set ext to its name extension
   set nFn to (newFileName & "." & ext)
   set its name to nFn
  end tell
 end tell
 set tmp to my splitString(oldAlias as text, ":")
 set the last item of tmp to nFn
 return my joinList(tmp, ":")
end renameFile

No comments in code, I do not want to spoil your fun!

I needed while writing an export script for Aperture. Here is how I used it after a photo was exported from Aperture:

tell application "Aperture"
 set dstFile to (export imageSel using export setting defExportSetting to fldAlbum)
end tell
set dstFile to my renameFile(dstFile, imgId)

Viewing latest article 1
Browse Latest Browse All 3

Trending Articles