As I am new to AppleScript, I would like some (a lot) of help with the following Mail problem:
In the Subject line, I need the Julian Date. Kindly, and one of your contributors supplied me with this script:
set jDay to do shell script “date +%j”
set jYear to do shell script “date +%y”
set theSubject to jYear & jDay & “/”
tell application “Mail”
set theNewMessage to make new outgoing message with properties {subject:theSubject}
tell theNewMessage
– Default is false. Determines whether the compose window will
– show on the screen or whether it will happen in the background.
set visible to true
end tell
end tell
So far, so good. In the text part of the email, I would like the following header:
Line1: XX XXXX then same Julian date as in Subject:
Line2: X ddhhmmX MMMYY - all from computer’s clock
Line3: XX XXXXXXX
Line4: XX XXXXXXX
Line5: XX
(X=alphabetic input)
Any assistance would be greatly appreciated
Hello:
This script is not terribly elegant, and I apologize for that. Please let me know if this is close to what you are looking for:
tell application "Mail"
set date_list to my MakeDates()
set theNewMessage to make new outgoing message with properties {subject:(date_list's item 1)}
tell theNewMessage
-- Default is false. Determines whether the compose window will
-- show on the screen or whether it will happen in the background.
set content of theNewMessage to (" XX XXXX " & (date_list's item 1) & return & "X " & (date_list's item 2) & "X " & (date_list's item 3) & return & "XX XXXXXXX" & return & "XX XXXXXXX" & return & "XX" & return)
set visible to true
end tell
end tell
to MakeDates()
set jDay to do shell script "date +%j"
set jYear to do shell script "date +%y"
set theSubject to jYear & jDay & "/"
set to_day to (current date)
set n_date_1 to (my FixDigits(to_day's day) & my FixDigits((to_day's time string)'s word 1) & my FixDigits((to_day's time string)'s word 2)) as string
set n_date_2 to ((to_day's month as string)'s characters 1 thru 3 as string) & (to_day's year as string)'s characters 3 thru 4 as string
return {theSubject, n_date_1, n_date_2}
end MakeDates
to FixDigits(d)
if (count d) < 2 then
set d to "0" & d as string
end if
return d
end FixDigits
Good luck, I hope this helps.
here an attempt for a shorter version (+ ‘X’- strings input dialogs):
tell application "Mail"
set theSubject to do shell script "date +\"%y%j/\""
tell (current date) to set {m, h, d, Mo, Yr} to ¬
{it's minutes, it's hours, it's day, text 1 thru 3 of (it's month as string) as string, (it's year) - 2000}
set theLines to {}
repeat with thisLine in {"Input line 1:", "Input line 2 - first part:", "Input line 2 - 2nd part:", "Input line 3:", "Input line 4:", "Input line 5:"}
set aLine to (text returned of (display dialog thisLine default answer ""))
if aLine ≠"" then
copy aLine & space to end of theLines
else
copy aLine to end of theLines -- to avoid leading space if 'aLine' is an empty string
end if
end repeat
set ddhhmm_MMMYY to ¬
(do shell script "printf {\"%02i%02i%02i %s%s%02i\"," & d & "," & h & "," & m & ",\"" & (item 3 of theLines) & "\",\"" & Mo & "\"," & Yr & "}")
set theContent to ¬
(item 1 of theLines & theSubject & return & item 2 of theLines & ddhhmm_MMMYY & return & item 4 of theLines & return & item 5 of theLines & return & item 6 of theLines & return)
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theContent}
set theNewMessage's visible to true
end tell
D.
… or maybe?
...
set ddhhmm_MMMYY to do shell script "date +\"%d%H%M " & (item 3 of theLines) & "%h%y\""
...