Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Run AppleScript without freezing interface

Run AppleScript without freezing interface
Thread Tools
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Jan 26, 2005, 11:03 AM
 
I wrote the following simple script for use as a sleep timer for iTunes:
Code:
tell application "iTunes" set answer to text returned of (display dialog "Enter the desired delay in minutes" default answer "10") delay (answer * 60) playpause end tell
The only problem is that when I run it through the script menu in iTunes, the iTunes interface freezes for the duration of the delay. Is there any way I can make this run "in the background" or something, so that I can still control iTunes during the countdown?
     
hayesk
Guest
Status:
Reply With Quote
Jan 26, 2005, 08:50 PM
 
Try putting all that stuff outside of the tell block.

set answer to text returned of ...
delay (answer * 60)
tell application "iTunes" to playpause


I don't know if this will work, but try it out and let us know.
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Jan 26, 2005, 09:48 PM
 
Nope, that didn't do it. Good idea, though.
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jan 26, 2005, 10:25 PM
 
The wrong answer is a variant on what hayesk said, separate the tell blocks so you are not telling iTunes to delay (a method that actively eats processor cycles, by the way):
Code:
tell application "iTunes" play end tell delay 5 tell application "iTunes" stop end tell
The proper way of doing something like this is to use "on idle" methods. There is quite a bit of documentation out there on this once you know that magic phrase, so I will leave you to it.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:22 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,