• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
My script won't be running stably
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

My script won't be running stably


  • Subject: My script won't be running stably
  • From: ILJA SHEBALIN <email@hidden>
  • Date: Mon, 20 Mar 2017 23:59:13 +0200

Hello,
My script wakes me up at the time prescribed by me by playing my selected tune. All works fine when tested within ScriptEditor, also when testing it by triggering from the scripts menu icon on menu bar. In fact it used to work as intended. Since writing the script I took into account that computer herself needs to leave Sleep Mode before activating the script I included the "do shell script" command (seen on the screenshot attached). System wake up time is set at 30 sec countdown to alarm trigger time to give the script a room to resume. 
A strange thing is that tomorrow it was the second time that while computer woke flawlessly the part that activates QuickTime Player to play a selected file failed. Console was of no use either to at least drop a hint to where to look up for a cause of such behavior. The only thing that may (?) bear some relation is that I switch off my router for a night, so the very first thing around the wake up time Console spits on me  are the references to applepushserviced about some stream error (which I guess is nothing to be worried of as the result of the WiFi being disconnected; or is it?). Here's my script. Could please tell me, what's wrong?

The script is as following:
==========================================
if wakeup_tune is missing value then
display dialog "Select an alarm tune"
end if
repeat
set wakeup time to display dialog "Enter wake up time" & return & return & "Formats accepted as below" & return return & "mmicidtyy hours:minutes' & return & "hours:minutes AM/PM (if current day)" & return & "June 25 hours:minutes AM/PM (if current year)" default answer wakeup_date buttons "{Cancel", "Continue"} default button "Continue"
set requested_date to text returned of wakeup_time
try
set wakeupDate to date requested_date
exit repeat
on error
display dialog "Invalid date format. Enter date as set up in your System Preferences"
try
on error number -128
return
end try
end try
end repeat
repeat
set wakeup_tune to choose file with prompt "SELECT AUDIO FILE FOR WAKE UP TUNE" of type {"public.audio"} default location alias "Macintosh HD:Users:user_name:Music"
set wakeup_tune to wakeup_tune as text
tell application 'Finder" to set song_name to name of file wakeup_tune
display dialog "You selected" & space & quote & song_name & quote & " for alarm." buttons ("Select another", "OK") default button "OK"
if button returned of result is "OK" then exit repeat
end repeat
set message_dialog to display dialog "You will be woken up at' & space & wakeupDate & return & "You will be woken up with" & space & quote & song_name & quote & "." buttons ("Cancel", "OK") default button "OK'
If button returned of message_dialog is "Cancel" then return

#date formatting for the shell command that overrides Sleep Mode for use in localized systems with non-US date formatting. If  the US date formatting is your native you probably won't need assembling Unix_long_date variable as in this script.

set locale_Date to date requested_date
set short_date to short date string of result
set time string to time string of locale_Date
set Unix_day to text 1 thru 2 of short_date
set Unix_month to text 4 thru 5 of short_date
set Unix_year to text 7 thru 8 of short_date
set Unix_short_Date to Unix_month & "/" & Unix_day & "/" & Unix_year
set localeDateAdjusted to locale_Date - 0,5 * minutes
set timeStringAdjusted to time string of localeDateAdjusted
set Unix_long_date to Unix_short_date & space & (timeStringAdjusted as text)
do shell script "sudo pmset schedule wake" & quote & Unix_Iong_date & quote password my_password with administrator privileges
repeat until (current date) ≥ wakeupDate
delay 10
end repeat
tell application id "com.apple.QuickTimePlayerX"
activate
open file wakeup_tune
tell document named song_name
set track_time to (get duration)
play
end tell
delay track_time
quit
end tell
set wakeup_tune to missing value

===========================================================

Sincerely Yours,

 ILYA SHEBALIN




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: My script won't be running stably
      • From: Luther Fuller <email@hidden>
    • Re: My script won't be running stably
      • From: Yvan KOENIG <email@hidden>
    • Re: My script won't be running stably
      • From: Yvan KOENIG <email@hidden>
    • Re: My script won't be running stably
      • From: Robert Poland <email@hidden>
  • Prev by Date: Re: strange difference in compilation of two Foundation classes in ASObjC
  • Next by Date: Re: My script won't be running stably
  • Previous by thread: Re: strange difference in compilation of two Foundation classes in ASObjC
  • Next by thread: Re: My script won't be running stably
  • Index(es):
    • Date
    • Thread