AppleScript: saving scripts
Just as there are multiple ways to save Automator workflows, there are also multiple ways to save AppleScripts. In this how-to, I will show you ways in which you can save your AppleScripts for future use.Read on for all the details.
Saving as a Script
You can save an AppleScript as an actual script file by going to File > Save; and choose "Script" from the file format drop-down box. When you save your script as the ".scpt" file, you will be able to open it back up at any time and continue work on it (similar to a text document) using whatever script editor you like.

You can also save your scripts as an application file (or .app file) so that you may double-click on them to run the script; just like a real application. To do this, go to File > Save; and choose "Application" from the drop-down menu. You may notice that there is also an "Application Bundle" format. If you have ever right-clicked on an application and chosen "Show Package Contents," then you have an idea of what this option does. It will allow you to have a file structure for your Application (this is known as a application fork).

What's with the options?
The "Run Only" option allows you to protect your scripts when you are distributing them; it compiles (or converts your script into something that only the computer can read) your script so that no one can open and edit it. Please note, this can be over come by a decompiler (however, I have no knowledge of an AppleScript decompiler at this time).
The "Stay Open" option is only available under certain formats (mainly the application and application bundle formats); and allows the script to stay open after it runs. This is only used under certain circumstances, mainly those which require an idle state.
The "Startup Screen" allows the scripter to give details about what the application will do and allow the user to either quit the script or go ahead and run it. The details about the application are set by using a description field.
Let's build an Application!
Now that I've told you a little about saving AppleScripts, let's build a script and save it as an application. We'll build a script that tells the Finder to display a dialog asking to continue and then use one of the system events that I showed you earlier. Type the script exactly as shown:
tell application "Finder" to display dialog "Would you like to Logout?"
tell application "System Events" to log out
Once you have it typed, let's save the application. Go to File > Save; choose "Application" from the file format drop-down box. When you have it saved, double-click on it's icon. The application will run and display a Finder dialog box asking you "Would you like to Logout?" if you click "OK" it will logout the current user, and if you click "Cancel," it will stop the script and quit the application. 
Congratulations, you've just made your first AppleScript application!
[Update:] One of our readers, Nik, reminded me that when you save an AppleScript as an "Application" only, it will NOT be saved as a universal application, instead, it will be formated as a PowerPC app. However, if you use the "Application bundle" format, you will save your AppleScript as a universal application (meaning it can run on both PPC & Intel Macs).
Share
Just as there are multiple ways to save Automator workflows, there are also multiple ways to save AppleScripts. In this how-to, I will show...
Add a Comment
Hi there, sorry for my ignorance. I am just trying to install your script... I have downloaded your EmailMovieViaEntourage.scpt and have popped it into the 'Entourage Script Menu Items' Folder. I have restarted both Entourage and QuickTime Pro. What else to have to do to make the export to Entourage work? Thanks heaps in advance.
January 26 2008 at 12:42 AM Report abuse Permalink rate up rate down ReplyI am loving all of these Applescript HowTos! A few days before these lessons started being published, I decided that I was going to learn Appplescript. Of course, I was very pleased to find out that you guys at TUAW are doing this! Great job Cory! Keep it up!
January 13 2008 at 4:03 PM Report abuse Permalink rate up rate down ReplyOne thing you left out: If you save an an application, rather than a bundle, your application will be a PPC application. Only app bundles are Universal. It makes a big difference on launch time and even on performance with larger scripts.
January 13 2008 at 2:05 PM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
- Used Apple MacBook Pro 2.4GHz 15" LED Laptop for $1,030 + $29 s&h
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



3 Comments