MACSCRPT Archives

February 2007

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Joe Barwell <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Wed, 28 Feb 2007 21:54:17 +1300
Content-Type:
text/plain
Parts/Attachments:
text/plain (97 lines)
On Mon, 26 Feb 2007, "J.L.Slangen" <[log in to unmask]> wrote:

>On my computer the result of (current date) is (in dutch):
>date "maandag 26 februari 2007 16:13:43".
>So the date format is dd/mm/yyyy

On your computer, maybe. The date _string_ format is what you've set it to be in your date preferences. Similarly with your date object format (e.g. you could reset it to lead with the month).

>The statement:
>set d1 to "26/02/2007"
>sets the value of d1 to
>date "maandag 26 februari 2007 00:00:00"

No it doesn't:

set d1 to "26/02/2007"
class of d1 -- > string

>The value of user_date at the end of the following mini-program is:
>"26/02/2007" (Unicode (UTF-16) text)
>
>set dialog_text to "Enter date "
>set date_dialog to display dialog dialog_text default answer "dd/mm/ 
>yyyy"
>set user_date to text returned of date_dialog
>
>The value of d2 in
>set d2 to date user_date
>becomes: date "maandag 26 februari 2007 00:00:00"
>
>Put the mini program in a Finder tell-block and enter "02/03/2007":
>tell application "Finder"
>	set dialog_text to "Enter date "
>	set date_dialog to display dialog dialog_text default answer "dd/mm/ 
>yyyy"
>	set user_date2 to text returned of date_dialog
>	set d3 to date user_date2
>	end tell
>and you will get an error: Can't make "02/03/2007" into type date.
>(The class of user_date2 is Unicode text)
>
>Now leave out "set d3 to date user_date2", and put it after the tell- 
>block.
>
>tell application "Finder"
>	
>	set dialog_text to "Enter date "
>	set date_dialog to display dialog dialog_text default answer "dd/mm/ 
>yyyy"
>	set user_date2 to text returned of date_dialog
>end tell
>set d3 to date user_date2
>
>and the value of d3 is the date:
>date "vrijdag 2 maart 2007 00:00:00"
>
>The problem is that the Finder dictionary tells me that "date  
>string" ( type string) can get me the date portion of a date-time  
>value as text.

It is unfortunate that Finder appears to be interfering with your date/date string manipulations, which after all do not require a Finder tell wrapper at all:

set dialog_text to "Enter date "
set date_dialog to display dialog dialog_text default answer "dd/mm/yyyy"
set user_date2 to text returned of date_dialog
set d3 to date user_date2

Or:

tell application "Finder"
	set dialog_text to "Enter date "
	set date_dialog to display dialog dialog_text default answer "dd/mm/yyyy"
	set user_date2 to text returned of date_dialog
	tell me to set d3 to date user_date2
end tell

>Why then is the following script not working?
>
>tell application "Finder"
>	set dialog_text to "Enter date "
>	set date_dialog to display dialog dialog_text default answer "dd/mm/ 
>yyyy"
>	set user_date2 to text returned of date_dialog as string
>	set d3 to date string of user_date2
>end tell
>
>I appreciate any enlightenment

I'm afraid I cannot tell you why Finder's tell wrapper interferes. Perhaps the terminology in Finder's dictionary, used for obtaining the dates of Finder objects (e.g. file creation dates & mod. dates), clashes with the terminology used in the Standard Additions osax (formerly Current Date osax) for date manipulations (NB, it is this tool and not Finder which is performing the date object manipulations for you in your script). <shrug> This problem with manipulating date objects inside a Finder tell wrapper dates back to at least AS 1.1.1 & OS 7.5, & so may well have been there from the beginning. Luckily, as I have shown above, you can either avoid placing your date manipulations inside a Finder tell wrapper, or else use a 'tell me' wrapper, so it should not prove too great a hindrance to your scripting.

Cheers!

Joe

Selected from Ambrose Bierce's "Devil's Dictionary":
RECREATION, n. -- A particular kind of dejection to relieve a general fatigue.

ATOM RSS1 RSS2