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 > Apple Script and a 3 minute timer?

Apple Script and a 3 minute timer?
Thread Tools
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Nov 15, 2001, 11:14 PM
 
This is a startup script someone asked me to make for them... (What it is supposed to do)
--------
open iTunes
play something in iTunes
open Limewire, and hide it
open Mail

after 3 minutes bring Limewire to the front
lauch Seti
---------
I can do everyting on here, except the 3 having the thing bring Limewire to the front after 3 minutes. Is this even possible, do I perhaps have to program a simple program that waits for 3 minutes and then brings Limewire to the front. I would really rather have all of this in Applescript, instead of programming something in C++.
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Nov 16, 2001, 03:31 AM
 
You can do it a couple of ways.

The simplest is use delay:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
-- do something
delay <font color = blue>180</font> -- pause for <font color = blue>3</font> minutes
-- do something else
</font>[/code]

The alternative is to use a code timer:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
set theTime to current date
-- do something
repeat until current date &gt;= (theTime + <font color = blue>180</font>)
end repeat
-- do something else
</font>[/code]

In the latter form, the script sits in a loop until 'current date' is greater than/equal to (the saved date + 180 seconds)
Gods don't kill people - people with Gods kill people.
     
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Nov 16, 2001, 09:15 PM
 
Wow, that is perfect, exactly what I was looking for!!!


Thanks...
     
Mac Enthusiast
Join Date: Aug 1999
Location: Calgary, Alberta, Canada
Status: Offline
Reply With Quote
Nov 16, 2001, 11:07 PM
 
Although the repeat will work, it will gobble up a lot more processing power than the delay command. Unless you need to do something during the "pause", the delay command is more processor friendly.
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Nov 16, 2001, 11:18 PM
 
This is slightly off topic.. but if you want to show AppleScript code, you can use this script, it requires the clipboard to html osax from osaxen.com... I also have a version that gives you pure html rather than just UBB code, to use this script, save it as an applet. Then whenever you want to post a script, copy the script, double click on the applet, wait till it beeps, then you have UBB code:


on run
   set theConvert to convert the clipboard to html
   set the clipboard to ((my replaceSubstrings({"&lt;", "&gt;", " ", "&not;", "&amp;", tab}, {"[", "]", "&nbsp;", "¬", "&", "&nbsp;&nbsp;"}, theConvert)) as string)
   delay 0.4
   beep
 end run
 
 on replaceSubstrings(searchString, replaceString, thestring)
   repeat with i from 1 to length of searchString
     set oldDelim to AppleScript's text item delimiters
     set AppleScript's text item delimiters to (item i of searchString)
     set tempList to text items of thestring
     set AppleScript's text item delimiters to (item i of replaceString)
     set thestring to tempList as string
     set AppleScript's text item delimiters to oldDelim
   end repeat
   return thestring
 end replaceSubstrings


BTW, the above formatting was all generated by the script above.
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Nov 17, 2001, 01:44 AM
 
Originally posted by King Chung Huang:
<STRONG>Although the repeat will work, it will gobble up a lot more processing power than the delay command. Unless you need to do something during the "pause", the delay command is more processor friendly.</STRONG>
You're right that the repeat loop is more processor intensive since it's continually calling current date to check its value.

However, delay wasn't added to the standard dictionary until AppleScript 1.4 (I think?). Earlier versions will fail to compile delay, necessitating the use of a third-party osax or the repeat loop.
Gods don't kill people - people with Gods kill people.
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Nov 17, 2001, 01:47 AM
 
Originally posted by King Chung Huang:
<STRONG>Although the repeat will work, it will gobble up a lot more processing power than the delay command. Unless you need to do something during the "pause", the delay command is more processor friendly.</STRONG>
You're right that the repeat loop is more processor intensive since it's continually calling current date to check its value.

However, delay wasn't added to the standard dictionary until AppleScript 1.4 (I think?). Earlier versions will fail to compile delay, necessitating the use of a third-party osax or the repeat loop.
Gods don't kill people - people with Gods kill people.
     
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Nov 17, 2001, 01:52 PM
 
Thanks for posting that script, I am copying and compiling it right now.

And yes, I think I will use the delay, because this guy I am making the script for is having something being run in the background till it is ready, which is after 3 minutes, so he needs the extra cycles. He has a new enough computer that he will have the updated applescript on it.

I am sure there will be a time when I will use the repeat loop as well, so thanks for that.

Oh and I need to minimize an iTunes window. Does anyone have a clip of a script that can do that?
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Nov 17, 2001, 10:55 PM
 
Originally posted by 11011001:
<STRONG>Oh and I need to minimize an iTunes window. Does anyone have a clip of a script that can do that?</STRONG>
Either of the three depending on what OS you are in...

tell application "iTunes"
   set collapsed of window 1 to true
end tell

tell application "iTunes"
   set zoomed of window 1 to true
end tell

tell application "iTunes"
   set minimized of window 1 to true
end tell

[ 11-17-2001: Message edited by: Synotic ]
     
Mac Elite
Join Date: May 2001
Location: Up north
Status: Offline
Reply With Quote
Nov 21, 2001, 11:11 PM
 
Excellent, that is what I thought it was... or close too, I was just doing something wrong.

Well now I can get the thing to work without giving any errors, but the trouble is iTunes won't respond to the command, I suspect it can't...
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 24, 2001, 07:13 AM
 
If you're talking about the minimizing script, it works fine for me.

tell application "iTunes"
set collapsed of window "iTunes" to true
set collapsed of window "Equalizer" to true
end tell

The windows kindly zoom down into the Dock, and all is right in the world.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:54 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2