简体   繁体   中英

issues with date command in Xcode cocoa applescript application

I am trying to do some math using the "date" command. But fist i need to turn text input if a date "MM/DD/YY" into something I can work with. In applescript I can do this:

    set MyTempTextInfo to "12/12/12"
    set MyTempTextInfo to (date MyTempTextInfo) as string
    display dialog MyTempTextInfo -- just to confirm another way of my answer

No issues and gives me the answer: "Wednesday, December 12, 2012 at 12:00:00 AM"

If I do this in Xcode cocoa app:

on buttonPresson_(sender)
    set MyTempTextInfo to (date "12/12/12") as string
    display dialog MyTempTextInfo
end buttonPresson

No issues and gives me the pop-up answer: "Wednesday, December 12, 2012 at 12:00:00 AM"

Now if I try to give it a variable in Xcode cocoa app... no go.

on buttonPresson_(sender)
    set MyTempTextInfo to "12/12/12"
    set MyTempTextInfo to (date MyTempTextInfo) as string
    display dialog MyTempTextInfo
end buttonPresson

* -[AppDelegate buttonPresson:]: Can't make «script» into type string. (error -1700)

What am I missing. I have tried making MyTempTextInfo as text / string and still errors. Anyone have any idea?

Update

I also found this version has the same error

on buttonPresson_(sender)
    set MyTempTextInfo to (date ("12/12/12")) as string
    display dialog MyTempTextInfo
end buttonPresson

* -[AppDelegate buttonPresson:]: Can't make «script» into type string. (error -1700)

I found a working solution for the moment. If I am wrong feel free to let me know.

on buttonPresson_(sender)
    set MyTempTextInfo to "12/12/12" as text
    set MyTempTextInfo to (current application's date MyTempTextInfo as date) as string
    display dialog MyTempTextInfo
end buttonPresson

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM