And if your using Yosemite and using that code regularly, say for logging, you could use this instead:
use framework "Foundation"
set theFormatter to current application's NSDateFormatter's alloc()'s init()
theFormatter's setDateFormat:"MMM_dd_yyyy_HH:mm:ss_z" -- Nov_24_2014_16:03:20_PST
set theDate to current application's NSDate's |date|()
(theFormatter's stringFromDate:theDate) as text
Just because it runs about 15-20 times faster, or more than 50 times faster if you create the formatter once.
Hi Shane! What is this? It’s not pure AppleScript, is it? I’ve already seen that “new” language and I wonder what it is and how to learn it. It sounds to be much faster and somehow easier though it requires clearly some learning.
It’s AppleScriptObjC – basically calling Cocoa/Objective-C via AppleScript. As of Yosemite you can mix it with any other AS code (in Mavericks you had to store it in scripting libraries, and before that you had to write Xcode projects). So I guess it’s pseudo-vanilla.
It is faster for some things, although not all things by any means. And I wouldn’t call it easier (unless the alternative is sed or awk;)), although it’s also not rocket science. But it does give you access to lots of powerful stuff.
It sounds like a plug, but the main resource I can point you to is my book:
Thanks for the input. I shall take time to read deeper later on, when I get some “free” time. Just to understand the thing: does it allow the scripter to reach some Objective-C components of applications that are not pure AS scriptable? Or it has nothing to do with the app code? I mean where does, for instance, the current application’s NSDateFormatter’s alloc()'s init() come from? Do I need to learn Obj-C prior to go further? Sorry for hijacking the original post.
It gets at the components apps get at, but not within other apps. It’s more about bypassing apps, in a way, or doing things apps can’t do. A bit like do shell script in that respect.
NSDateFormatter is a Cocoa class – essentially part of the OS. So that line is allocating and initializing an instance of the NSDateFormatter class.
No, but you need to understand a bit about how it works, and the concepts of classes and instances.
Thank you, Shane! I’ve searched the Net for more info and details about all that. I found a picture of you and it’s nice to see how people look like in real I’ve also read you’re a real specialist of AS and ASOC. Which was not really a discovery to me
I’ll really try to find time to dig into ASOC. I’m still on ML and am not always keen on upgrading rapidly to the newest version of Mac OS (or whatever application). Each time I upgrade sth, some of scripts are just ruined for one reason or another. One cannot be on every front. Thanks again for the info.