Stairways Software Icon

Stairways Software

Excellence In Software For Over Ten Years – Only with a Mac

Using AppleScript to Edit With a specified application

Recently a user asked me how they could use Interarchy to edit files in two different applications. They knew that each extension can have its own editor (for example, .txt files can be edited with BBEdit and .css files can be edited with StyleMaster), but in this case they wanted to choose on the fly which editor they wanted, for example choosing BBEdit or TextMate depending on the particular action they wanted to perform.

AppleScript allows you to get the selected URL list in Interarchy and also to edit a list of URLs and specify the editor, so the solution is to create two AppleScripts, one for BBEdit and one for TextMate, and then assign them hot keys (perhaps using Keyboard Maestro). The AppleScript is:

tell application "Interarchy"
    set sel to selection of window 1
    set urls to {}
    repeat with e in sel
        set urls to urls & {url of e}
    end repeat
    ftpedit urls editor "R*ch"
end tell

BTW, do not let the ftp in “ftpedit” fool you, this will work with any protocol.

The editor code is the creator type of the application, “R*ch” for BBEdit and “TxMt” for TextMate. If you do not know the creator code for the application, you can look in the application‘s bundle, in the Contents folder, for the PkgInfo file, which consists of 8 characters, “APPL” (for Application) followed by the creator code.

You could, of course, create a single AppleScript which asked for the creator code, or provided a set of possible applications, or whatever. That is the beauty of AppleScript and scriptable applications - you can speed up your workflow by customizing to exactly how you work.

Posted Thursday, December 7, 2006. Permalink. 2 Comments.

Comments

Thanks very much for the tip. Being a complete AppleScript newbie, I very much appreciate to see concrete examples of how Interarchy can be extended using just a few lines of code. Please post more :)

Posted Friday, December 8, 2006 12:57 AM by Bertrand Mansion.

There are some typos in your applescript code. Here is a working version for TextMate:

tell application "Interarchy"

set selected to selection of window 1

set urls to {}

repeat with myfile in selected

set urls to urls & url of myfile

end repeat

ftpedit urls editor "TxMt"

end tell

And for BBEdit:

tell application "Interarchy"

set selected to selection of window 1

set urls to {}

repeat with myfile in selected

set urls to urls & url of myfile

end repeat

ftpedit urls editor "R*ch"

end tell

Thanks.

Posted Wednesday, January 10, 2007 02:48 AM by Bertrand Mansion.

Post Comment

Name: (optional)
URL: (optional)
Email: (optional, not published)
   
CAPTCHA: eight six seven three (required)
  To prove you are human, please enter the number as digits (ie, 1-9).
Comment:
  You can use some HTML tags such as <b>, <i>, and <a href="">.
We reserve the right to remove any offensive or inappropriate comments.
Due to spam issues, comments are initially invisible until we review them,
you can see them (background red) and we can see them, but no one else.

Comment Preview

None yet.

Buy Now

User Database

Stairways