Ian Svoboda Ian Svoboda - 26 days ago 6
AppleScript Question

Transmit 4 AppleScript - Close new Document when script completes

I've been experimenting a bit with CodeKit and I wanted to insure that my changes were auto-uploading to my web server.

To solve this, I have written an AppleScript recently that waits until files are processed and then runs on the entire project directory.

The problem I'm having is that my script keeps opening up new "windows". Ideally, I'd like to never have more than a single window open at one time, so I thought I could have the script close the new document that's created. However, I'm struggling with the syntax.

Here is my code:

tell application "Transmit"
set myFave to item 1 of (favorites whose name is "Favorite Name")
set myRules to (skip rules whose enabled is true)

tell current tab of (make new document at end)
connect to myFave
change location of local browser to path ""
change location of remote browser to path ""
synchronize local browser to remote browser using skip rules myRules

close remote browser
end tell
end tell


So my question(s) are:


  1. Is there a better/more efficient way to do what I'm trying to do?

  2. If I'm on track, how can I set that new document being created to close once the script is done running?


Answer

I ended up answering my own question!

The answer was surprisingly simple. I noticed in the AppleScript dictionary for Transmit that there was a "close" method which relates to documents (which was the thing I was trying to close).

I was puzzled at first because I thought I'd need to specify what I was closing. But ultimately, I just added "close" after "close remote browser".

tell application "Transmit"
    set myFave to item 1 of (favorites whose name is "TitanHost")
    set myRules to (skip rules whose enabled is true)

    tell current tab of (make new document at end)
        connect to myFave
        change location of local browser to path ""
        change location of remote browser to path ""
        synchronize local browser to remote browser using skip rules myRules

        close remote browser
        close
    end tell

end tell

I hope this helps someone else!

Comments