Im stumped.
I have code that is getting a future date. But I can’t figure out how to get this date into a Text field with a date formatter.
set AppleScript's text item delimiters to "/"
set dateItems to text items of (short date string of (current date))
set AppleScript's text item delimiters to ""
set theDate to ((item 1 of dateItems) + 1) & "/" & item 2 of dateItems & "/20" & item 3 of dateItems as string
--dueDate's setStringValue_(theDate)
set thisDueDate to current application's NSDate's |date|()
set newDueDate to thisDueDate's dateByAddingTimeInterval_(14 * 24 * 60 * 60)
log newDueDate
dueDate's setStringValue_(newDueDate)
I get the following error
2011-07-26 08:13:48.928 CMSA XML[7453:a0f] -[__NSCFDate length]: unrecognized selector sent to instance 0x2010ac5e0
2011-07-26 08:13:48.940 CMSA XML[7453:a0f] *** -[CMSA_XMLAppDelegate applicationWillFinishLaunching:]: -[__NSCFDate length]: unrecognized selector sent to instance 0x2010ac5e0 (error -10000)
Well, i’m guessing you need a string to pass to the setStringValue_ method. You could try converting the NSDate object before with an NSDateFormatter, like this:
tell current application's NSDateFormatter to set newDueDateFormatted to localizedStringFromDate_dateStyle_timeStyle_(newDueDate, current application's NSDateFormatterLongStyle, current application's NSDateFormatterLongStyle)
this returns an NSString and then you don’t need a formatter on your text field.
Here are the options for the formatter:
current application’s NSDateFormatterNoStyle
current application’s NSDateFormatterShortStyle
current application’s NSDateFormatterMediumStyle
current application’s NSDateFormatterLongStyle
current application’s NSDateFormatterFullStyle
or have you tried coercing the value first to string? like this:
dueDate's setStringValue_(((newDueDate) as string))
Hope this helps. Good luck!
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
The best way to do this is to just use setObjectValue_(newDueDate) instead of setStringValue (newDueDate is an NSDate object, not a string).
Ric