11/21/2023 0 Comments Hammerspoon scriptsOne, despite Apple’s attempt to improve Folder Actions’ reliability, I’m still not convinced. It has been possible to rig up something similar for a long time with Apple’s built-in Folder Actions, but there’s a couple of reasons why I prefer Hammerspoon for this task. With only a few lines of code in Hammerspoon’s config file, you can set up an alert that will fire whenever the LaunchAgents folder is modified. Apps like my DetectX and FastTasks 2 keep an eye on these areas by design, warning you in the Changes and History logs when files have been added or removed from them – but Hammerspoon can add an extra little ‘canary’ warning for you too. One of the ‘danger zones’ on your mac – by which I mean one of the favourite places for adware, malware and other assorted badwares to infect – is your LaunchAgents folders. Instead, Hammerspoon bridges directly to Apple APIs using the lua scripting language, and that allows you to do some interesting things. Meet Hammerspoon, which differs significantly in not using Apple Events to do many of its automation tasks. I recently discovered a neat little extra automation tool on top of the familiar ones of AppleScript, Automator, and script runners like FastScripts and Keyboard Maestro. *not all Cocoa frameworks nor all Objective-C objects can be bridged to, but pretty much all the most useful ones are available. You can do anything you want with ASObjC. I think the best way to think of ASObjC was recently summed up by Sal Saghoian, when he said that ASObjC is “…the ultimate duct tape. Property : a reference to current application's All you need to know about these is for each kind of Objective-C object you want to use (NSString, NSArray, whatever*), you’ll want a property statement for it at the beginning of the script. These latter are peculiar to the ASObjC translation, and don’t have a counterpart in pure Objective-C. You’ll notice in Script Editor there is a 'use' statement (equivalent to Objective-C’s ‘import’), and there’s also a whole load of property statements. You call instance methods by putting the instance in front of the method just as you would in regular Objective-C (e.g, see line 3 of the examples).Īs you can see in the screenshot below showing Xcode and Script Editor, they work in the same way. Type declaration is done via the idiom 'set to 's ', which returns an instance of the object just as it would normally. The main peculiarity is the use of possessive word forms and that variable attribution is done by using "set X to Y" rather than "X = Y". NSUserNotificationCenter's defaultUserNotificationCenter()'s deliverNotification:notifĪs you can see, there’s a direct 1-to-1 correspondence, with the 6 statements in Objective-C paralleled by the 6 statements in AppleScriptObjC. Set notif to NSUserNotification's alloc's init Set aString to aString's stringByAppendingString:bString Set bString to NSString's stringWithString:" world" Set aString to NSString's stringWithString:"hello" If you’re battling on in Apple’s default Script Editor, you’ll need to do the translation manually.īy way of example, then, here’s some original Objective-C, and below it, a translation that would work in Script Editor:ĪString = If you use LateNight Software’s Script Debugger for scripting, you’ll already know that the work is done for you by the app’s built-in code completion. The problem that using ASObjC presents anyone familiar with Objective-C is how to translate ‘pure’ Objective-C into the dialect that Script Editor (and other applescript runners like FastScripts, Keyboard Maestro, Automator, etc) can understand. app), and also mix whatever scripting language you prefer with calls to Cocoa’s APIs.* scpt file (or scptd bundle or AppleScript. The point of doing so would be that one could package Objective-C code in a. In plainer English, you can use Objective-C in an AppleScript without any AppleScript whatsoever! It is actually just a dialect of Objective-C that will be accepted in the (Apple)Script Editor and can be run by an instance of the AppleScript component. If that’s you, bear in mind that AppleScriptObjC isn’t really “AppleScript + Objective-C” at all. Of course, some people have suffered miserably at the hands of AppleScript in the past, and even though the thought of scripting with access to Cocoa APIs through Objective-C is tempting, they fear the AppleScript side of it. Is it me, or is AppleScript experiencing something of an Indian Summer? It seems everywhere I go, people are talking more about macOS automation, AppleScript and even Apple’s curious hybrid syntax AppleScriptObjC (ASObjC).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |