5

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.

4 Answers 4

1

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 ...

0

I can think of two:

  1. Extension names are meant to be associated with your application of choice. If you change your applescripts to be the default .txt app, you will be either opening up plain text with AppleScript Editor, or opening up applescripts with TextEdit when you double click. Of course you can resort to context menu, but some may consider it an nuisance.

To take it further, an user can save all his files without any extension, and scroll through all his applications from Adobe Photoshop to VLC everytime, ad absurdum.

  1. In less likely cases, an app needs the extension to know what to do with the file. For instance, TextMate can automatically apply the correct syntax highlight for .scpt files, and BetterTouchTool has an option to "Open Application, File, Apple Script". If the script is saved as .txt, it will be displayed rather than executed.

That's my 2 cents. Btw, if you cannot change the default save option, you can always create a macro with say Keyboard Maestro, and bind it to keyboard shortcut CMD+S. This way, the default save operation will be overridden by your custom sequence of actions that changes the file type.

2
  • On 10.6.8 they are both treated the same by Finder, see edit. You keyboard suggestion is interesting though... Commented Sep 25, 2014 at 20:12
  • Got it. I've never seen .applescript before. I also thought of a way to do it free. Use BetterTouchTool, create shortcut CMD+S that launches an applescript. The script will keystroke s {command down} and then select the correct dropdown menu before returning the cursor to filename box, type in .applescript and CMD+A. I guess you can use an Automator Service, but I don't know if it will override the existing CMD+S. BTT definitely will. Commented Sep 25, 2014 at 20:26
0
  1. Manually create a blank file with the extension .applescript

  2. Open the .applescript file. It will automatically open with the Script Editor, and future saves will retain plain text format.

Command line example:

touch foo.applescript
open foo.applescript
0

My own experience is that Script Editor will always do what I don't particularly want, which I have addressed by conceding the field.

But since I want spotlight access to at least some of my scripts, I created a script to save the current document as a text file in a storage folder I created that contains only these .applescript files.

tell application "Script Editor"
    set vPath to (path to documents folder) & "as_stuffs:savedtexts:" as text
    
    set d1 to document 1
    set fN to name of d1        
    save d1 as "text" in file (vPath & fN & " _dmp.applescript")
end tell

I access it from the script menu and it works reliably. The actual .scpt file gets filed manually according to its purpose or the app it works primarily with but all of the text files get saved in a single folder with an added '_dmp' in their filename so I can easily distinguish them. I also created a script that opens the folder (along with the .scpt folder and the 'user scripts' folder in the Library) although after a while I stopped using it.

This lets me not worry about saving scripts as .scpt but also get an appropriately named .applescript with no muss and no fuss.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .