Saving applescripts as scripts versus text

applescript

When saving a script in Applescript Editor, it defaults to the Script file format. The file produced is binary and cannot be indexed by Spotlight. So if I want to search a script based on a word used in the code, I cannot since script code is not indexed.

On the other hand I can save as text, but I must remember to change the format option every time!

So what is the advantage of saving in Script format and is it possible to make Text the default?

I am using the editor in 10.6.8 Snow Leopard

EDIT:

Text format files are saved with the extension .applescript and are setup to open by default with the Applescript Editor, same as with .scpt.

Best Answer

This has been a goal for many an Applescripter for a long time.

Not sure anyone has hit the holly grail without using a third party scripting app with a Spotlight indexer..

I have tried a few things in the past but this thread prompted me again to have another go.

I now normally try and save all my applescripts in one places, in a Scripts folder in my Documents folder and also use Hazel to watch place like my Documents folder and desktop for scpt files and move them into the Scripts folder.

My new idea is to run a shell script that will be passed a scpt file that is saved in my Normal scripts folder as a normal scpt file and use the shell command osadecompile to decompile and read the file. Then create a text version in my new Script Text folder.

The code I am using is:

fname=`basename "$1"`

echo "`osadecompile "$1"`"  > "/Users/UserName/Documents/Scripts/Script Text/$fname".txt

Hazel conveniently uses $1 for the file path of the file being passed. And I use the command basename to get the file name.

In Hazel it looks like this.

enter image description here

Notice I am using a date last modified condition with 5 minutes.

This is to try and catch any edits I do.

The nice thing I found is when I find the text file with the code I am looking for, I can either copy the text, refer to it, or find the scpt file easily because I have the same file name in the text file file name.

i.e

display iTunes artwork.scpt

display iTunes artwork.scpt.txt

This idea should be able to be used with other folder watching apps or hopefully give you some inspiration ...