Applescript to do different things at different times

Hi,
I just started applecript a few weeks ago and I need some help.
Here is the script I use as my morning wake up call.
Functions:
1. Time
2. Weather
3. Reads new mail
say "Good Morning Sir"
say "It is " & getTimeInHoursAndMinutes() using "Alex"
on getTimeInHoursAndMinutes()
-- Get the "hour"
set timeStr to time string of (current date)
set Pos to offset of ":" in timeStr
set theHour to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
-- Get the "minute"
set Pos to offset of ":" in timeStr
set theMin to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
--Get "AM or PM"
set Pos to offset of " " in timeStr
set theSfx to characters (Pos + 1) through end of timeStr as string
return (theHour & ":" & theMin & " " & theSfx) as string
end getTimeInHoursAndMinutes
tell application "Mail" to launch
set CityCode to 2459115
set t_format to "C"
set v_format to "S"
set a_format to "Y"
set IURL to "http://weather.yahooapis.com/forecastrss?w=" & CityCode
set file_content to (do shell script "curl " & IURL)
--looking for the line with actual condition
set theText to text ((offset of "yweather:condition" in file_content) + 1) thru -1 of file_content
set sub_1 to text ((offset of "\"" in theText) + 1) thru -1 of theText
set actual_condition to text 1 thru ((offset of "\"" in sub_1) - 1) of sub_1
set sub_1a to text ((offset of "temp=" in sub_1)) thru -1 of sub_1
set sub_1b to text ((offset of "\"" in sub_1a) + 1) thru -1 of sub_1a
set actual_temp to text 1 thru ((offset of "\"" in sub_1b) - 1) of sub_1b
if t_format is equal to "C" then
set actual_temp to (5 / 9) * (actual_temp - 32) as integer
end if
set theText to text ((offset of "yweather:forecast" in file_content) + 1) thru -1 of file_content
set sub_2 to text ((offset of "\"" in theText) + 1) thru -1 of theText
set today_min_temp to word 9 of sub_2
set today_max_temp to word 12 of sub_2
if t_format is equal to "C" then
set today_min_temp to (5 / 9) * (today_min_temp - 32) as integer
set today_max_temp to (5 / 9) * (today_max_temp - 32) as integer
end if
set sub_3 to text ((offset of "text" in sub_2) + 1) thru -1 of sub_2
set sub_4 to text ((offset of "\"" in sub_3) + 1) thru -1 of sub_3
set today_forecast to text 1 thru ((offset of "\"" in sub_4) - 1) of sub_4
set sub_5 to text ((offset of "yweather:forecast" in sub_4) + 1) thru -1 of sub_4
set sub_6 to text ((offset of "\"" in sub_5) + 1) thru -1 of sub_5
set tomorrow_min_temp to word 9 of sub_6
set tomorrow_max_temp to word 12 of sub_6
if t_format is equal to "C" then
set tomorrow_min_temp to (5 / 9) * (tomorrow_min_temp - 32) as integer
set tomorrow_max_temp to (5 / 9) * (tomorrow_max_temp - 32) as integer
end if
set sub_7 to text ((offset of "text" in sub_6) + 1) thru -1 of sub_6
set sub_8 to text ((offset of "\"" in sub_7) + 1) thru -1 of sub_7
set tomorrow_forecast to text 1 thru ((offset of "\"" in sub_8) - 1) of sub_8
if a_format is equal to "Y" then
say "The current conditions in New York City is " & actual_condition & " ,and the current temperture is " & actual_temp & " degrees"
end if
tell application "Mail"
set unreadMessages to (get every message of mailbox "INBOX" of account "[email protected]" whose read status is false)
set numberofmessages to (count of (every message of mailbox "INBOX" of account "[email protected]" whose read status is false))
if (count of (every message of mailbox "INBOX" of account "[email protected]" whose read status is false)) is 1 then
tell application "Mail"
say "There is only " & numberofmessages & " new email"
repeat with eachMessage in unreadMessages
delay 1
say "From! "
say (get sender of eachMessage)
say "Subject."
say (get subject of eachMessage)
set read status of eachMessage to true
end repeat
end tell
else if (count of (every message of mailbox "INBOX" of account "[email protected]" whose read status is false)) is greater than 1 then
tell application "Mail"
say "There are " & numberofmessages & " new messages"
repeat with eachMessage in unreadMessages
delay 1
say "From! "
say (get sender of eachMessage)
say "Subject."
say (get subject of eachMessage)
set read status of eachMessage to true
end repeat
end tell
else
say "There are no new messages"
end if
end tell
I was wondering if there is a script that could determine the time and say good afternoon after the time is 1:00pm and good evening after the time is 6:00pm instead of saying good morning all day.
Thanks for your help!!

set theHours to hours of the (current date)
if theHours > 18 then
          say "good evening"
else if theHours > 12 then
          say "good afternoon"
else if theHours > 6 then
          say "good Morning"
else if theHours > 0 then
          say "go back to bed!"
end if

Similar Messages

  • I recently purchased FaceTime from the Application Store. After approx. ±10 meg, the application resets and starts downloading again. I have tried to download it at different times of the day but with the same results. I have been in contact with Apple su

    I recently purchased FaceTime from the Application Store. After approx. ±10 meg, the application resets and starts downloading again. I have tried to download it at different times of the day but with the same results. I have been in contact with Apple support and have tried different options with the same result. I cannot download a new Version because in my Purchased List the applicaiton (FaceTime) is still there, and because I have halted it it tells me to resume. I can’t, because the same thing is going to happen. I have tried all the various troubleshooting tips supplied by my ISP and also Apple Support with no luck. I am currently working on a IMac OS 10.6.7. Has anybody got any ideas? Any suggestion would help. Thanks

    Amol Soni wrote:
    As I said, I tried everything what the manual says, but hard luck. I have taken an appointment for today, lets see what happens.
    Also there is no activity on unit when I use the remote. The unit is stuck on the first page itself where we have to choose the language. The unit seems to be fine to me but the real problem is remote does'nt have activity. The IR is not responding while pressing any of the button.
    Good luck with your appointment.
    Not much consolation but even new products can have issues and might need a trip to a store to return/replace.
    The reason i asked about the LED on the AppleTV is that occasionally it thinks it's paired with a specific remote and ignores others - the unpair keypress I described is quick and free.
    AC

  • How to design EDW for source systems from different Time-Zones

    How to design EDW for source systems from different Time-Zones?
    Suppose IT landscape has a global BW in New York, and source systems in americas, europe and asia, then how the time-zones effect on time related things like delta selections on date or timestamp etc.

    As you said BW is global in NY, your source system must be global too. People from various locations can connect to same source system and thus timestamps for delta is always maintained as 1 single time. We have same scenario in our project. Our R/3 system is used by users in US and Europe. So we run deltas twice in day to make sure we got deltas from both locations.
    If scenarios was such that all locations connect to separate R/3 system, then obviously you have multiple queues. That is unique delta queue for each source system so deltas will be pulled as per data in respective queues.
    Abhijit

  • Different time zones in the same calendar subscription

    Dear kind helpers,
    To state my problem as clear as possible, I need to be a bit long. Sorry for that.
    I registered to a calendar displaying the rugby schedule for the VI nations tournament:
    -> http://www.rbs6nations.com/tools/calendars/sixnations-fixtures-6n-all.ics
    from the official web site:
    -> http://www.rbs6nations.com/en/matchcentre/downloadable_fixture_list.php
    The only thing you need to know about this tournament is that it involves 6 teams (hence the name):
    - 2 on the continent, then at GMT+1 (France and Italy),
    - 4 on the British Isles (Englands, Walles, Scotland and Ireland), then at GMT+0
    I think all of these nations have the same summer / winter shifts.
    I'm on the continent, Central European Time for the time zone support feature on iCal (OS 10.9.1).
    I guess it's GMT+1 plus winter shift at the moment.
    I notice the same following problem on my iPod (iOs 5.1.1), sync through iCloud
    Here the problem : it seems all the games are in local times !
    For instance, a game in the Islands (Scotland, England, ...) appears at 5pm whereas I would like it to appear at 6pm (so the time is correctly displayed for British Isles, not for the continent) / a game on the continent (France or Italy) will appear at 5pm and I'm fine because it's right the correct time in my time zone. I've no idea how a game which takes place on the continent appears in the British Isles :-(
    So a few questions :
    - am I clear about the problem ?
    - is it a problem from iCal or from the subscription itself ?
    - in case it's iCal, is there a way to fix the trouble ?
    PS : I experienced the same problem with an other subscription a few years ago ; it was also for a european championship schedule across different time zones displayed in the same calendar. This one was discontinued.
    Thanks in advance.

    Hi,
    This is an issue with the subscription itself. The times for the events are set in 'floating' time and whatever time zone you use it iCal will show the event as being at that time local time (which obviously won't be right unless you are in the correct time zone).
    I could post a more technical explanation if you like.
    Best wishes
    John M

  • Objects to show at different times on a slide not showing up

    Hi  Everyone,
    I hope this problem is minor and that I’m just missing a small step but here it goes…
    I’m using Captivate 4 and I’ve only been using it on one particular computer. I updated a captivate project that I’ve been working on since September and I’ve finished all the edits (added a picture, changed a few words) as requested by colleauges when all of a sudden, some objects that were suppose to show at different times on the slide were not showing up at all. The frustrating part is I actually finished the project! When I do a preview within the edit view, the objects appear as it should, however, when I publish it or do a preview on wepage, the objects are not appearing at all (ie a word at 10 sec, another at 20 sec). Anway, there were only 3 slides acting like this, all with objects are suppose to show up at different times on the slide (these were not the slides that I recently edited). My video works fine, my quiz works fine, and I’ve uploaded an initial version of my work on a Pathlore LMS with no problems (publish specs: flash 8, AS2).
    I have several other projects that are less complicated (ie no video, no objects showing at different times within the slide) and they are OK. I’ve checked on other computers and same problem.
    I tried deleting the slides, and redoing it again within the same project but still wont work I tried copying everthing on a new project with the same size with no luck.
    I tried making a 2 slide project with objects showing up at different times and it works.
    Is my project corrupted in some way? What are the possible culprits for this problem?
    I really hope I don’t have to start from scratch…
    Thanks in advance!

    Hi there
    While it's certainly possible that the project has somehow become corrupt, you might find that simply closing and restarting Captivate changes things.
    Have you tried that? I've seen it where bits and pieces are suddenly missing. After I restarted, things were just fine again.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Publishing Two Different Sites at Two Different Times

    OK, I want to be able to publish my podcast made through iWeb and my blog page made through iWeb at two different times. Basically, I am waiting for a few things to happen before I want to start my podcast and before that happens I want to update my blog. How do you make this happen? I'm using iWeb 08. Thanks a lot!

    OK, I want to be able to publish my podcast made through iWeb and my blog page made through iWeb at two different times. Basically, I am waiting for a few things to happen before I want to start my podcast and before that happens I want to update my blog. How do you make this happen? I'm using iWeb 08. Thanks a lot!

  • How to read from DAQ in different time intervals

    Hello,
    I am currently using LabVIEW 2010. I am new to LabView.
    I have 9 thermocouples I want to record the temperature from and create a graph.
    For one graph I want to graph the data every second for the duration of about 1.25 hours. For the other I want to record and graph the data every 2 minutes for a duration of 30 minutes. The temperature then would be ramped up in an oven and set to a higher temperature. When it is stabilized, recording of the data again will begin again at intervals of 2 minutes for the duration of 30 minutes.
    The first is only to see the real time temperature variation while the program is recording and running. The second graph and data is what I will use to analyze.
    What I need help in is finding out how you can read from the DAQmx at two different time intervals. I tried two parallel loops with each one graphing the two separate graphs I need with a delay time. Those two parallel loops where then surrounded by another while loop. The result is that the outside loop waits until both loops are finished so I do not get the correct results for the real time data graph.
    Is there a way to call on the DAQ data you need at the time interval you desire? Any suggestions to solve this problem? Thank you for your time and help.

    You are on the right track.  Sample the data at the fastest rate and send it to the 1st graph.  For the slower graph, take a sample from the faster data at your desired time interval.  You could use a timer and a case structure for something quick and easy and still have everything run in the same loop.  You could use two loops running at different speeds, it is just a little more involved and a few other things to consider. 

  • Can the central system and the sender system at different time zone?

    We have a control(i.e. central) system which is 6 hours ahead of the sender system.
    When processing step "analyse tables in sender system", we get short dumps immediately at  control , sender and receiver.
    On the sender, the short dump reads:
    Runtime Errors         CALL_FUNCTION_SEND_ERROR                       
    Date and Time          01/15/2011 16:09:05                                                                               
    Short text                                                           
         " " (I/Oerror)                                                                               
    What happened?                                                       
         "CPIC-CALL: 'ThCMSEND' : cmRc=18 thRc=0#Statistics not active "                                                                               
    An error occurred when executing a Remote Function Call.
    On  the central system the short dump reads:
    Runtime Errors         CALL_FUNCTION_REMOTE_ERROR
    Date and Time          15.01.2011 22:09:00
    Short text
         "Field symbol has not yet been assigned."
    On the receiver the short dump reads:
    Runtime Errors         GETWA_NOT_ASSIGNED                                         
    Date and Time          01/15/2011 22:09:00                                                                               
    Short text                                                                       
         Field symbol has not yet been assigned.                                                                               
    What happened?                                                                   
         Error in the ABAP Application Program                                                                               
    The current ABAP program "SAPLCNVTDMS_BW_FUNCTIONS_REM" had to be terminated  .
    We never get this error before on this step.  The only thing I can think of is that the sender and the central system
    are at different time zone.
    Please share your experience.
    Thanks!

    Hi,
    By looking at the runtime error , the reason of the dump should not be the timestamp diff .
    You can create an OSS ticket with SAP for further analysis.
    Also, there can be data consistency issues due to time diff .
    Cheers
    Sandeep

  • Been on hold two different times for more that 30 minutes....Followed the instructions and my phone said that activation has failed.  FRUSTRATED

    how do i activate my 6? I followed the instructions and it said my activation failed...now on hold for 2 different times.  been screwing with this for 3 hours.

    I highly doubt that the VZW CS reps are sitting by idly letting people stew on hold.  I'm sure there are loads of people just like us that have questions, but they don't know how to get online and figure things out.  Yes, people like this have iPhones.  My point is, I wouldn't blame this on Verizon's Customer Service.  If you're truly frustrated, take the suggestion given and try it. 

  • I would like to know how can I set songs in iTunes to play at different times automatically during the day. i.e. one song at 10am the other at 10:30am etc..

    I would like to know how can I set songs in iTunes to play at different times automatically during the day. i.e. one song at 10am the other at 10:30am etc..

  • How can I save my data and the date,the time into the same file when I run this VI at different times?

    I use a translation stage for the experiment.For each user in the lab the stage position (to start an experiment) is different.I defined one end of the stage as zero. I want to save the position , date and time of the stage with respect to zero.I want all these in one file, nd everytime I run it it should save to the same file, like this:
    2/12/03 16:04 13567
    2/13/03 10:15 35678
    So I will track the position from day to day.If naybody helps, I appreciate it.Thanks.

    evolution wrote in message news:<[email protected]>...
    > How can I save my data and the date,the time into the same file when
    > I run this VI at different times?
    >
    > I use a translation stage for the experiment.For each user in the lab
    > the stage position (to start an experiment) is different.I defined one
    > end of the stage as zero. I want to save the position , date and time
    > of the stage with respect to zero.I want all these in one file, nd
    > everytime I run it it should save to the same file, like this:
    > 2/12/03 16:04 13567
    > 2/13/03 10:15 35678
    >
    > So I will track the position from day to day.If naybody helps, I
    > appreciate it.Thanks.
    Hi,
    I know the function "write to spreadsheet file.vi"
    can append the data
    to file. You can use the "concatenate strings" to display the date,
    time as well as data... Hope this help.
    Regards,
    celery

  • Some, but not all, podcasts existing on the iPod no longer appear in iTunes. Different podcasts have been affected at different times, after changes in the state of the iPod. Only podcasts are affected.

    I have not seen this precise issue addressed anywhere. I don’t know if it’s an iTunes or an iPod problem:
    - Some, but not all, podcasts existing on the iPod no longer appear in iTunes;
      this, after normal behavior for more than a year since purchase of the iPod.
    - Different podcasts have been affected at different times, after changes in the state of the iPod.
    - Only podcasts are affected.
    - This concerns an iPod nano 6th gen. and iTunes 11.0.2 (26) on System 10.6.8
    - The only change to iTunes, the Mac, or the iPod is that just before this condition began
      I’d begun syncing an iPhone via iTunes.
    I sync manually (“manually manage music and videos”). The first time this happened, I wanted to delete seventeen podcast episodes (all belonging to one podcast) existing on the iPod — but they didn’t show up in iTunes. I tried re-downloading them and re-syncing, to see if the new versions would somehow “re-link” to iTunes. They didn’t. Only one — new — episode appeared in iTunes.
    I ultimately reset the iPod and manually resynced all the podcasts I currently had on iTunes. That worked, though I had to painstakingly add in all the other content deleted by the reset.
    So: after that reset and manual sync, all podcasts and episodes on the iPod were visible to iTunes and I was able to delete the podcast and its — now 18 — episodes I’d wanted to get rid of to begin with. But the next time I connected the iPod, only 8 podcast episodes out of 21 episodes total existing on the iPod were visible to iTunes. These are different podcasts; I’d deleted the original “invisible” ones.
    By “visible,” I mean in the “Podcasts” list view under “[name]’s iPod” in the iTunes sidebar. If I select “[name]’s” iPod in the iTunes sidebar and the “Podcasts” tab, all podcasts and episodes are visible, though greyed out because I’m set to sync manually. It’s unclear to me if these are the podcasts on the iPod or those currently in iTunes, as they are currently the same. If I switch to syncing automatically, all content on the iPod will be lost again, so I’m not up to trying it at the moment.
    As I said,  this involves only podcasts. All other content on the iPod does appear in iTunes.

    I have the same problem- i see my movies in the ipod section in itunes and they even show as mpeg4 in the 'kind' section but they dont have that small TV icon next to them. if i play these in itunes, they play fine- but try playing them on the ipod and all you hear is the sound and no picture. All videos that i manually transfer work fine in the beginning- its when i hook up the ipod to the comp again and start itunes- they start showing up without the 'tv' icon!! i have to again transfer them from the itunes library to activate them as videos.
    Need Help!!!

  • How to make the counter count or start at different time

    Hi,
    How to let the counter count the time, that doesn't start at the same time ?
    This timing system is a sport timing system for canoe competition, it need to track 6 competitor that start at different time .
    I have a problem , I have 6 counter in a VI that use to track 6 competitor, but it start count at the same time, how to make it count separately for each competitor ?
    Do you guys know how to solve this problem ?
    Solved!
    Go to Solution.
    Attachments:
    multi competitor.zip ‏50 KB

    HI, 
    ya, i run it. I mean i know how to make it to 6 competitor already , and yes, it works but the time, it still count or start at the same time. I  need to run each competitor at different time , like this competitor A 20-2-2012.VI . This is the one i do but it cant put a stop button. once i put a stop button, the clock stop counting but the whole VI is running.
    Regadrs,
    Sam
    Attachments:
    competitor A 20-2-2012.vi ‏139 KB
    3switch 3-2-2012.vi ‏14 KB

  • How to create an event in two different time zones?

    Hello,
    I am traveling a lot and I would like to be able to enter the flight details in iCal - whether on my iPhone, iCloud, i... whatever. The problem is that I cannot manage to enter these details without calculating the time difference. Example:
    I am flying on Saturday from Frankfurt to Japan. My flight takes off at 19:00h local German time and arrives in Tokyo at 13:00h local time (in Japan)
    I can either specify the time zone for Germany or for Tokyo, but is there a way to enter the event from 19:00h German time to 13:00h Tokyo time?
    Thank you very much for your time.
    Larry

    Hi Alex,
    this applies only when the event takes place in one time zone, but in my case I start the event on one time zone and ends in a different time zone. As it is known, the airlines show always the local times on the ticket. Which means that I start my travel at 19:00h German time (UTC +2) and end it at 13:00h Tokyo time (UTC +9). When I create the event I can choose From Date/Time... To Date/Time and below I have Time zone. Ideally I should have two time zones, one for the start and another for the end.
    Since this situation only applies to travelling (I can't think of another case right now), I believe that Apple didn't take this into consideration.
    Any other thoughts/ideas? Other than manually calculating the difference, of course.

  • Write arrays into a text file in different columns at different times

    Hi,
              I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).
    Do you have an idea to solve my problem?
    Thank you

    A file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.
    So:
    read file into 2D array
    insert columns using array operations
    write resulting 2D array to file again.
    (Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)
    LabVIEW Champion . Do more with less code and in less time .

  • How to display different Time Statement forms in ITS service PZ04

    Hi all,
    I am working on a underlyinge R/3 4.7 system and are working with standalone ITS and ESS 50.4. I am posting this question to find out if any of you has experience with my problem.
    The business wishes to use the ITS transation PZ04 standard and wish to be able to display different Time Statement forms in the transaction through customized variants for the report(RPTEDT00) that the PZ04 transaction executes. In the IMG it is posted that one variant has to be created called HRESS_TEDT00 and this works, but restricts the PZ04 transaction to always be called with this variant and therebye the same Time Statement form every time.
    I then by debugging found that the underlying ABAP code processed from SAP standard has a variable VARIANT that is hardcode to = HRESS_TEDT00.
    The question is: Is there anyway to setup the PZ04 transaction so that it can be dynamic decided which variant should be used, f.ex. from persons subarea from infotype 0001?
    Looking forward to here if anybody can help.
    Regards,
    Allan Brauer

    hi allan,
    cud u plz help me how to sort out this problem actually in mu company the same scenario is here need to be display pe51 form instead of standard hrforms.....
    plz help me how will i replace this "hrforms with pe51"..

Maybe you are looking for