Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to quit an application

I have a very simple Applescript written and saved as an application to quit GoodSync, a syncing program. When I run the script from within applescript the application quits. When I run the application as a stand alone it fires but does not quit the application.


any ideas?


tell application "GoodSync"


quit

end tell


The applicaton does not ask to save anything on quit.

I have used automator to the same end and it works as a stand alone application.


Eager to learn,

Thanks in advance,


Debbie

Posted on Feb 28, 2014 3:10 PM

Reply
15 replies

Mar 1, 2014 2:30 PM in response to singerdf

No idea why it is not working fro you. Don;t have GoodSync here but tried it as a saved app on Preview and it works fine.


Does Applescript know about GoodSync, does GoodSyns have an entry in the Applescript dictionary?


You could try adding saving no to the command


tell application "GoodSync" quit saving no


to see if that makes a difference. If not you'll have to resort to using a do shell script to quit the app


Something like

tell application "System Events"


set theID to (unix id of processes whose name is "GoodSync")

try


-- Should stop the application with no dialogs and no items saved.

do shell script "kill -9 " & theID

end try


end tell

(modified from MacScripter)


should work

Mar 1, 2014 2:34 PM in response to Frank Caggiano

Thanks, Frank. I looked in the Libary and GoodSync does not have an entry.


GoodSync does not ask to save on quit. When I run the script from with in Applescript it works fine. It only has issues when I double click the app from the Applications folder. To add confusion, I also created an automator application and that runs fine, ie, quits GoodSync.


I am wondering if I need to keep Applescript open longer when the stand alone app is running? Like put a delay in to wait for GoodSync to quit.


I would like to make this work with out the shell script. But I will file away your suggestion.


Debbie

Mar 1, 2014 3:44 PM in response to Frank Caggiano

Tried quit saving no, I apologize that I did not include that in my last response. I will try the second suggestion when I am back at my computer and report back.


I was simply trying to gain a better understanding as to why the script runs from the Applescript Editor but will not run correctly, ie quit the app, when launched on its own.


Be back soon and thanks for helping,


Debbie

Mar 1, 2014 6:54 PM in response to singerdf

Since all you are really triyng to do is Quit an open application it should be poosible to do this within Automator without using Applescript at all. Launch Automator and search for an action called Quit Application. When you drop it into the pane on the right side you can choose the application you want to quit. That command works with most, if not all, applications. It can be saved as an applican and run with a double click.

Mar 2, 2014 4:32 AM in response to Frank Caggiano

Frank,


The Shell works but sends back a bunch of errors.

tell application "System Events"


get unix id of every process whose name = "GoodSync"


--> {4370}


do shell script "kill -9 4370"


--> error number -1708


«event ascrgdut»


--> error number -1708


do shell script "kill -9 4370"


--> error number -10004

end tell

tell current application


do shell script "kill -9 4370"


--> ""

end tell

Result:

""


I am not familiar enough with the coding and errors of AppleScript to determine if I need to worry. The computer also told me that my external hard drive was not ejected properly not long after I ran this script.


Thank you again,


Debbie

Mar 2, 2014 4:42 AM in response to singerdf

That's strange as I downloaded GoodSync and tested it on my own machine, without problems.


However, I noticed that when you install GoodSync it asks for admin permission (which I did not allow).


As an alternative (I also noticed your problems with Frank's shell script version, so...) try this one-liner:



do shell script "killall GoodSync"



this works for me. If it doesn't work for you, try the superuser version:



do shell script "killall GoodSync" with administrator privileges



This one will require you to enter an admin password, but should kill it dead.

Mar 2, 2014 4:45 AM in response to Phil Stokes

Thanks, Phil. I will try. My confusion continues to be that it runs and quits the app when run from AppleScript Editor. It fires from the stand alone script as I can see it launch in my dock, but the app remains open.


My goal is that GoodSync will quit when it is done with its own run. So I need this piece to work seemlessly before, I work on the next piece.


I am sure I gave it admin permission as I am the admin and only user on my computer.


Be Back with results shortly.


Debbie

Mar 2, 2014 8:37 AM in response to singerdf

Hi Debbie,


there is a reason for this, but I must admit to it being lost in memory. One of the forum gurus might come up with it, but if you want to find it for yourself, and indeed if you're serious about learning applescript one or both of the following two sources will have the answer:


This one's free:

AppleScript Language Guide


This one isn't, but is worth its weight in (AppleScript) gold:


http://www.amazon.com/AppleScript-The-Definitive-Guide-Edition/dp/0596102119


Despite its age, most of what's in here is not in any other book.


Good luck. 🙂

Applescript to quit an application

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.