• 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
Re: Coping with Date format variations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coping with Date format variations


  • Subject: Re: Coping with Date format variations
  • From: Robert Poland <email@hidden>
  • Date: Tue, 25 May 2010 06:46:35 -0600

Thanks Michelle,

I appreciate your advice.

My first thought was to reject your example as it didn't seem to apply then I realized that's a better way to do what I wanted. And yes I ignored am/pm on purpose.

Here's the entire Script;

on run
main()
end run

on main()
set muteVolume to 1 -- a 0 here interferes with the mute command
set middleVolume to 50
set highVolume to 100
set nowTime to time of (current date)
set pmFlag to false
set myPath to POSIX file "/Library/Scripts/Universal Scripts/setSoundVolumePrefs"


tell (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution") to set {newR, newB} to {word 2 as number, word 4 as number} -- get screen size for monitor
-- newR = 1560 for 27" monitor
if newR > 1700 then set middleVolume to 40 -- 50 was too loud with 27" iMac


script SetSoundVolumePrefs
property WakeUpTime : ""
property SleepTime : ""
end script


try
set SetSoundVolumePrefs to load script file myPath
on error
set WakeUpTime of SetSoundVolumePrefs to text returned of (display dialog "wakeUpTime: (use military format, '6:01') " default answer "" buttons {"OK", "Cancel"} default button "OK")
set SleepTime of SetSoundVolumePrefs to text returned of (display dialog "sleepTime: (use military format, '21:01')" default answer "" buttons {"OK", "Cancel"} default button "OK")
store script SetSoundVolumePrefs in file myPath replacing yes
end try


set WakeUpTime to WakeUpTime of SetSoundVolumePrefs
set SleepTime to SleepTime of SetSoundVolumePrefs


-- convert to numbers
set tees to {WakeUpTime, SleepTime}
set tees to my decoupe(tees)
set {WakeUpTime, SleepTime} to result


if (nowTime is less than SleepTime) and (nowTime is greater than WakeUpTime) then
set soundVolume to middleVolume
else -- After bed time
set soundVolume to muteVolume
end if


set volume output volume (soundVolume)
if soundVolume ≠ muteVolume then
set volume output muted (false)
else
beep
set volume output muted (true)
end if
return
end main

on decoupe(tees) -- t = time
set output to {}
set AppleScript's text item delimiters to ":"
repeat with t in tees
set {h, m} to text items of t
copy ((m as integer) + ((h as integer) * 60)) * 60 to end of output
end repeat
set AppleScript's text item delimiters to "" -- restore
return output
end decoupe


On May 24, 2010, at 10:49 PM, Michelle Steiner wrote:

On May 24, 2010, at 8:22 PM, Robert Poland wrote:

As noticed by others the handler is used several times so that's why the text item delimiters were done that way. 

That introduces another potential problem; if you're going to use text item delimiters in other handlers, there may be a conflict.

Also, you might think about passing all the parameters at once, so the handler is called only once, and loops within the handler.

set WakeUpTimes to {"6:31", "8:49", "7:13", "3:26"}
set WakeUpTimes to my decoupe(WakeUpTimes)

on decoupe(tees) -- t = time
set output to {}
set AppleScript's text item delimiters to ":"
repeat with t in tees
set {h, m} to text items of t
copy ((m as integer) + ((h as integer) * 60)) * 60 to end of output
end repeat
set AppleScript's text item delimiters to "" -- restore
return output
end decoupe

Then you can process each item of the returned list.

-- Michelle

Robert Poland - Fort Collins, CO



 _______________________________________________
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

References: 
 >Re: Coping with Date format variations (From: Shane Stanley <email@hidden>)
 >Re: Coping with Date format variations (From: Luther Fuller <email@hidden>)
 >Re: Coping with Date format variations (From: "Mark J. Reed" <email@hidden>)
 >Re: Coping with Date format variations (From: LuKreme <email@hidden>)
 >Re: Coping with Date format variations (From: "Mark J. Reed" <email@hidden>)
 >Re: Coping with Date format variations (From: Luther Fuller <email@hidden>)
 >Re: Coping with Date format variations (From: Robert Poland <email@hidden>)
 >Re: Coping with Date format variations (From: Michelle Steiner <email@hidden>)
 >Re: Coping with Date format variations (From: Robert Poland <email@hidden>)
 >Re: Coping with Date format variations (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Coping with Date format variations
  • Next by Date: Sending raw Apple Events to Palm Desktop
  • Previous by thread: Re: Coping with Date format variations
  • Next by thread: Re: Coping with Date format variations
  • Index(es):
    • Date
    • Thread