|Feb 5, 2013, 10:52 AM||#1|
Help With Automating iTunes With A Set Of Scripts
Would anyone be willing to take a look at my AppleScript and help me figuring out how to resolve a couple errors I'm getting and also provide feedback as to if I should be doing something differently or better?
I'm attempting to write a set of scripts to automate iTunes. I have a script I saved as a "Stay Open" application named Launcher. The code for it looks like:
on idle if weekday of (current date) = Sunday then --insert code to call Sunday Script else if weekday of (current date) = Saturday then -- insert code to call Saturday Script else -- all other days must be Monday through Friday, or midweek days -- insert code to call midweek script tell application "midweek1" activate end tell end if -- delays 86400 seconds, or 24 hours return 86400 -- 86400 = 24 hours -- using this line will call the code between on idle and end idle, correct? end idle
Here is my issue with Launcher: when it calls "midweek1", Launcher goes to "Application Not Responding" mode until "midweek1" finishes running. Once "midweek1" is done running, Launcher comes out of its Not Responding state, and then prompts me with an error "Connection is invalid".
It's my understanding that with the connection is invalid message, Launcher is trying to communicate with "midweek1" but it can't because "midweek1" is closed. I'm not sure why it would be trying to communicate with "midweek1" as I thought that once the code inside an "on idle" block would not run again until the return time value has been met. Another thing I can't figure out here, is why the "midweek1" application is relaunched and run after I click "okay" on the Connection is invalid" dialog box.
Here is the code for "midweek1". I have midweek1 saved as an application, no "run only" "stay open" checkboxes selected.
-- sets my target event times set startTime to "7:32:00AM" set stopTime to "8:02:00 AM" repeat while (current date) is less than date startTime delay 2 -- causes script to do nothing while current time is less than startTime end repeat -- startTime has been met set volume 3 delay 2 set volume 2 delay 2 set volume 1 delay 2 set volume 0 tell application "iTunes" activate set sound volume to 0 end tell set volume 0 delay 1 set volume 1 delay 1 set volume 2 delay 1 set volume 3 tell application "iTunes" activate next track set sound volume to 0 --Enter playlist name to be played exactly how it appears in iTunes between the quote marks tell playlist ("Classical") play end tell --Fade-up tell application "iTunes" set sound volume to 10 delay 1 set sound volume to 20 delay 1 set sound volume to 30 delay 1 set sound volume to 40 end tell end tell --waits until stopTime is called repeat while (current date) is less than date stopTime -- should be 60 delay 2 end repeat --Fades music down after stopTime is called --Fade-out tell application "iTunes" set sound volume to 30 delay 1 set sound volume to 20 delay 1 set sound volume to 10 delay 1 set sound volume to 0 end tell --Stops iTunes playback tell application "iTunes" stop end tell --Quits script quit
Thanks in advance for any help or input!! I really appreciate it!!
|Feb 5, 2013, 01:31 PM||#3|
Take a look at launchd to run your scripts at specific days of the week. The StartCalendarInterval key from the launchd.plist manual page has all the info.
Info : Timed Jobs Using launchd and Running a Job Periodically and launchd.plist OS X Manual Page
Space Corps Directive 34124
|Feb 5, 2013, 06:08 PM||#4|
Thanks! I will read up on those. From my initial viewing, that might be just the thing I am looking for!
I need a script launched every day, and before, I used iCal. But I feel that's sort of a clunky and painful way of doing it. So my thought was to write a script that runs every 24 hours to check the day of the week, and based on that detection launch some script.
On another note, I think I figured out the "Connection is invalid" error. Instead of using
activate application "midweek1"
launch application "midweek1" activate application "midweek1"
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Help With Automating Importing Songs into iTunes||mr-ska-jr||Mac Applications and Mac App Store||0||Dec 25, 2013 10:01 AM|
|Automating iTunes import with multiple users?||marc.garcia||Mac Basics and Help||5||Oct 26, 2013 11:48 AM|
|Resolved: HELP New iTunes update seems frozen RUNNING SCRIPTS||liquorice||Mac Basics and Help||4||Sep 19, 2013 05:38 AM|
|Automating user preferences?||omgitssum1||Mac Basics and Help||0||Jul 26, 2012 02:00 PM|
|automating a set of terminal ssh commands to a clickable icon?||Juz||OS X||2||Jun 4, 2012 09:08 AM|
All times are GMT -5. The time now is 10:31 AM.