This post will deal with what I consider a very concrete use of the ‘choose from list’ dialog. After reading this (and perhaps trying it out in the Script Editor) you will probably be totally confused (just kidding!!) It gets a little complicated, but it is basically a cut-and-paste script.
If you pay close attention to my comments, I’m sure you’ll understand most of what is going on and, after all, it’s understanding how a script works that allows you adapt it to other applications that you may have in mind.
So anyway, here it is:
set AppleScript's text item delimiters to ","
–this first line is needed, because it sets things up for extracting the info we need
set theLongDate to (current date)
set theLongDate to (date string of theLongDate)
–the next 2 lines set us up for calculating the numerical data for month and day
set currentMonth to (word 1 of text item 2 of theLongDate)
set currentDay to (word 2 of text item 2 of theLongDate)
–this gets the numerical value for the month
set currentYear to (word 1 of text item 3 of theLongDate)
set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with x from 1 to 12
if currentMonth = ((item x of monthList) as string) then
set theRequestNumber to (text -2 thru -1 of ("0" & x))
exit repeat
end if
end repeat
set currentMonth to theRequestNumber
set currentDay to (text -2 thru -1 of ("0" & currentDay))
set theShortDate to (currentMonth & "/" & currentDay & "/" & currentYear) as string
–previous code sets up the default text (current date in the form mm/dd/yyyy – something like ‘02/03/2009′) for dialog below :
set theDefaultDate to text returned of (display dialog "Enter a date in the form MM/DD/YYYY:" default answer theShortDate buttons {"Calc Date"} default button {"Calc Date"} giving up after 20)
–this line converts the text supplied by the dialog into class ‘date’ (the long form of the date, including the time):
set calcLongDate to date theDefaultDate
–this line extracts the date portion and leaves the time portion behind:
set calcLongDateTrunc to (date string of calcLongDate)
–this converts calcLongDateTrunc back into the form ‘text’ so that it can be displayed in a dialog:
set calcLongDateTrunc to calcLongDateTrunc as string
display dialog calcLongDateTrunc buttons {"Done"} default button {"Done"} giving up after 15
–yields – ‘Tuesday, February 3, 2009′
In my next post, I will shift gears and present an AppleScript which I have derived from one of my FileMaker programs, which serves as a convenient file backup program.
In conclusion, please note in my right sidebar (you may have to scroll), that in the future I will be featuring (here and there) little snippets of HyperTalk code (and others as they occur to me)
As always, if you have any questions or comments, contact me at: hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page


































Recent Comments