How can I create textedit doc and fill with date time data?

Discussion in 'Mac Programming' started by f11music, Mar 24, 2016.

Tags:
  1. f11music, Mar 24, 2016
    Last edited: Mar 24, 2016
  2. f11music, Mar 24, 2016
    Last edited: Mar 24, 2016

    f11music thread starter macrumors newbie

    Joined:
    Mar 24, 2016
    #2
    Just need to figure out how to get the hour in 2 digit format. Need it to be like 0300 0600 etc instead of like it is. How can I do that?

    set whichUrl to 0
    set fileNames to "1000hPa"
    set theStartDate to the date "Sunday, June 21, 2015 at 00:00:00"
    set theEndDate to theStartDate + (60 * 60 * 24 * 2)
    set theDate to theStartDate
    set theURL to "http://site.net/#"
    repeat until theDate = theEndDate
    set theURL to theURL & (the year of theDate as text) & "/" & (the month of theDate as number) & "/" & (the day of theDate as text) & "/"
    set theURL to theURL & (time of date (theDate as string))
    set theURL to theURL & "rest.html" & return
    set theDate to theDate + (60 * 60 * 3) --advance 3 hours
    --Open the URL in Safari

    tell application "Safari"
    activate
    set the URL of document 1 to theURL
    --Wait until it loads, then take a screenshot
    delay 8
    set picPath to ((POSIX path of (path to desktop)) & fileNames & "-" & whichUrl & ".jpg") as string
    do shell script "screencapture -tjpg " & quoted form of picPath
    end tell

    --Increase the counter for next time
    set whichUrl to whichUrl + 1
    end repeat
     
  3. f11music thread starter macrumors newbie

    Joined:
    Mar 24, 2016
    #3
    Well it's sort of a kludge but I got it working like this. COuldn't figure out a cleaner way to have the time in the format of HHMM

    set whichUrl to 0
    set fileNames to "1000hPa"
    set theStartDate to the date "Sunday, June 21, 2015 at 00:00:00"
    set theEndDate to theStartDate + (60 * 60 * 24 * 2)
    set theDate to theStartDate
    set theURL to "http://site.net/#"
    repeat until theDate = theEndDate
    set theURL to theURL & (the year of theDate as text) & "/" & (the month of theDate as number) & "/" & (the day of theDate as text) & "/"
    if (time of (theDate as date) = 0) then --1 digit hour so add 2 leading zeros
    set theURL to theURL & "00" & (round ((time of (theDate as date)) / 36))
    else
    if (time of (theDate as date) < 43200) then --1 digit hour so add leading zero
    set theURL to theURL & "0" & (round ((time of (theDate as date)) / 36))
    else
    set theURL to theURL & (round ((time of (theDate as date)) / 36))
    end if
    end if
    set theURL to theURL & "theres.html" & return
    set theDate to theDate + (60 * 60 * 3) --advance 3 hours

    tell application "Safari"
    activate
    set the URL of document 1 to theURL as text
    delay 8
    set picPath to ((POSIX path of (path to desktop)) & fileNames & "-" & whichUrl & ".jpg") as string
    do shell script "screencapture -tjpg " & quoted form of picPath
    end tell

    set theURL to "http://site.net/#"
    set whichUrl to whichUrl + 1
    end repeat
     

Share This Page