Re: My script won't be running stably
Re: My script won't be running stably
- Subject: Re: My script won't be running stably
- From: Yvan KOENIG <email@hidden>
- Date: Tue, 21 Mar 2017 17:47:06 +0100
Hello. ILJA SHEBALIN sent me this message :
Hi Yvan,
Thank you for your reply. Yes I realized these typos and edited them out, adding new comments to those of you who may wish to compile and run it on your machines. I then sent a corrected variant to another user who had replied but I don't know how to make it visible to all of the mailing list users. The corrected version looks this:
--------------------
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 & "mm/dd/yy 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:(*my home folder*):Music" #change the placeholder (*my home folder*) to the name of your home folder.
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
#bellow follows date formatting to pass to 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 done 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 "" with administrator privileges #to make it compile without disclosing personal sensitive information I left the quotes following the word "password" empty. You should type in your password before running the script.
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
--------------------
However there appeared another dimension to my issue,very unexpected and more on hardware side rather that on that of software. It turned out that SMC reset cured (knock the wood) this problem. I verified it by setting up the alarm again and it worked at the set time. Prior to that it worked but only when Sleep Time was set to a short span amidst overall active login session (that occurred as the result of me testing, checking the script to see what was wrong) but not when I put it to sleep for practical use.
I pass it with no change.
Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mardi 21 mars 2017 17:46:41
_______________________________________________
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