applescript stuck each time

Discussion in 'Mac Programming' started by ratch90, Dec 17, 2008.

  1. ratch90 macrumors newbie

    Oct 14, 2008
    Ok, so i made this applescript for xtorrent which starts it, and quits it every hour, so i can download without the speed limit..
    I made it very simple and it looks like this,

    tell application "Xtorrent" to activate
    delay 3550
    tell application "Xtorrent" to quit
    delay 30
    end repeat

    I also made a very simple interface for it, with a run and a quit button, but everytime I run the applescript it does everything i ask, but i can't quit it, only with force quit. So today I pasted it into Xcode
    and tried everything, button to button, but I just can't get it quit. I should be able to end the repeat when i push the stop button. like that I would be able to start it back later without having to force quit it each time.

    Alse I have been told, that Applescript is very limited in doing applications, maybe it would be better to do this in any other programming language, or is it possible to do this with applescript?

    Really thanx for all your help
  2. Sayer macrumors 6502a


    Jan 4, 2002
    Austin, TX
    When using "delay" your script, and thus the app, hangs until the delay is over. So the script can't be "stopped" because its waiting for the delay timeout.

    You can get around that by using the on idle event handler. You return a number from that handler that is a delay until the idle event is sent again. You can return 60 (seconds) and count from 1 to 60 and at 60 quit the app.

    It's been a while since I did that level of scripting, but I believe you return the number of whole seconds, not milliseconds or something.

    on idle
    set timeCount to timeCount + 1
    if timeCount > 60 then
    quit app
    end if
    return 60
    end idle

Share This Page