The life of AppleScript

MacWorld has an interesting article that questions whether AppleScript is alive and kickin or dead and Apple should move on and fill the void.

I personally don't think the language is dead. But it could be if Apple doesn't take it seriously. Things to improve: the language itself (why does it force the scripter to handle file paths?!), the script editor (either make XCode the script editor or make the current script editor a full featured editor and debugger), make implementing AppleScript easier for developers (no one will use it if it doesn't exist), and make AppleScript's recordability easier to implement (maybe power users can learn faster by watching than by reading, besides not everyone has the time to read, try, read some more, hang head, and repeat). Oh yeah, I almost forgot....more documentation (example scripts and snippets, and reference guides for each scriptable application and scripting addition).

Although its over a year old, Daniel Jalkut, the developer of MarsEdit, wrote an article noting that Apple appears to place more time and attention on improving JavaScript performance for WebKit than they do for the system wide scripting language, AppleScript. Although I agree with the sentiment, I disagree with the idea of making JavaScript the system wide scripting language. I think the major strength of AppleScript is its fairly easy to learn which means power users should be able to use it with minimal problems.

If anyone reading this agrees that AppleScript has major problems that don't seem to be getting the attention the language deserves, I encourage you to contact Apple or write up bugs and feature requests and let them know.

AppleScript's home

Recently I tried to visit www.apple.com/applescript only to find I was redirected to a page devoted to describing the applications included in Mac OS X, specifically Automator.

Because that seems odd to me I thought perhaps Apple moved it and mistakenly directed visitors to the wrong location. Using Google, I discovered that what appears to be the entire content of www.apple.com/applescript has been moved to www.macosxautomation.com and I don't understand why. But I thought I would mention it to my visitors in case others were having trouble finding AppleScript's home as well.

Editing version names and other news

Since I put this site up I have had a few people ask me for assistance with a script they are writing to automate Aperture. First, let me say I'm happy to hear users of Aperture are interested in automating Aperture as well as find this web site useful. And secondly, I am happy to help improve the content of this site using reader feedback.

A while ago I received a request for help from a reader/user that wanted to change an image version's Exif Image Date by 2 minutes. After thinking about the solution of his problem I realized that this script is far more useful than changing the Exif Image Date by 3 years. So I decided to remove my time shift script on the Metadata page that incremented the image date by 3 years with a script that will add 1 hour to the image date. Why not 2 minutes? Because I want to not only illustrate how to time shift but also provide a useful script to a wider audience. I assume more people will want to change their images' date in increments of an hour to deal with daylight savings time or a change in time zones than will want to change the minute or second. Either way, the modification required is very slight.

Another reader/user recently asked me a question concerning a script he was writing that will remove the file extension from the name of the image version. I thought it was strange that Aperture somehow placed the file extension in the image version name. After playing around with Batch Change, I realized if you change the image version name to the master filename, the images will be named something like: filename.cr2

Since some users of Aperture may see this as a problem and it can be created within the GUI of Aperture, I decided to a script that will get a selection of images and remove a file extension from the version name. You will need to modify the script so that it finds the particular file extension you want found. For those that may not realize where to change the script to handle your individual needs, I left a comment just below the line that should be modified. Enjoy.

Click to open example in the Script Editor applicationRemove file extension from the version name.

 tell application "Aperture"
 set imgSel to (get selection)
 end tell

 if imgSel is {} then
 
error "Please select an image."
 
else

  repeat with i from 1 to count of imgSel
 
set imgName to name of item i of imgSel
 
set newimgName to findAndReplace(".CR2", "", imgName)
 
--Replace .CR2 with the string you want to remove.

 
tell application "Aperture"
 
tell item i of imgSel
 
set name to newimgName
 
end tell
 
end tell
 
end repeat
 
end if

 
on findAndReplace(tofind, toreplace, TheString)
 
set ditd to text item delimiters
 
set text item delimiters to tofind
 
set textItems to text items of TheString
 
set text item delimiters to toreplace
 
if (class of TheString is string) then
 
set res to textItems as string
 
else -- if (class of TheString is Unicode text) then
 
set res to textItems as Unicode text
 
end if
 
set text item delimiters to ditd
  return res
 
end findAndReplace


DISCLAIMER: I outright stole the find and replace function from Nigel Garvey which was posted a forum post on MacScripter. Since it was posted on a forum of a site devoted to learning AppleScript and this site does not collection money, I assumed I was ok to posted the function here.

Export command and selection property

I recently received an email from a visitor wondering why his export script produced an error when attempting to export a single image out of Aperture.

From his email I realized I omitted a few valuable simple scripts from my collection of sample scripts that would have helped him answer several of his questions. Therefore I'm happy he emailed me as his feedback helps to improve this site.

I failed to have a simple selection script and a very simplistic export script. Both scripts have been added to the site. The selection script can be found at the bottom of the Basics page. And the new export script can be found at the top of the Exporting page.

One other thing I failed to mention about exporting images is the export command only handles lists of image versions. Attempting to export a single image will produce an error which was the root of the visitor's problem.

If your script generates an error but you feel everything should work, be sure to take a close look at the Applescript Dictionary for Aperture. The dictionary should provide all the necessary information to successfully use a command, class, or property. In this particular case the dictionary does state the export command exports a "List of image versions or projects to be exported." Overlooking something such as this is easy to do.