AppleScript: open frontmost file with another application

Posted by jacobianism on Stack Overflow See other posts from Stack Overflow or by jacobianism
Published on 2014-08-20T17:42:53Z Indexed on 2014/08/21 10:20 UTC
Read the original article Hit count: 131

Filed under:
|
|

I'd like to write an AppleScript program to do the following (Automator would be fine too):

I want to open the current active TextMate file (possibly there are several tabs open and other windows) with the application Transmit 2. (This will upload the file over FTP using Transmit's DockSend feature.)

Here I've used a specific application (TextMate) but ideally I'd like it to work for any file currently active in any application.

Ultimately I will assign a keyboard shortcut to run it.

Here's what I have so far:

tell application (path to frontmost application as text)
    set p to path of document 1
end tell

tell application "Finder"
     open POSIX file p using "Transmit 2"
end tell

I've tried many variants of this and nothing works.

EDIT: I have found this page: http://wiki.macromates.com/Main/Howtos and someone has made exactly the script I'm looking for:

tell application "Transmit" to open POSIX file "$TM_FILEPATH"

This is for Transmit [not 2] and I think for TextMate pre v2. I get the error (when using Transmit 2):

Transmit 2 got an error: AppleEvent handler failed.

One of the updates to v2 has broken it (not sure which one).

© Stack Overflow or respective owner

Related posts about applescript

Related posts about automator