How to show the NSUserNotification in command-line-tool program? - objective-c

I want to write a command-line-tool program that only shows the NSUserNotification. I've found out, that in order to show the NSUserNotification I need to create a Cocoa App and is not what I want.
I want to run my program at log-in in background, so that my notification is always visible. How can I do that without creating a Cocoa App?

These are the options I found...
Trick Mac OS X into allowing a notification from a command-line tool.
Trigger the notification using Applescript or a helper application.
Create an Automator workflow & execute it using the automator command.
Automator provides a better experience than Applescript. Didn't try the helper.

Related

Objective equivalent to AppleScript : Opening directory without bringing every finder window to from

There this AppleScript
tell application "Google Chrome" to set index of window 1 to 1
do shell script "open /Volumes"
Which opens a directory in Finder without bringing every onther Finder windows to the front.
Currently I'm using :
[[NSWorkspace sharedWorkspace] openURL:fileURL];
But it has the flaw to bring every Finder windows on the top of others.
Any idea how I could achieve the same behaviour as the AppleScript ?
You can always use NSAppleScript to run applescript code in Objective-C if Cocoa doesn't provide the functionality you want.
At a guess, -[NSWorkspace openURL:] also sends the application an activate event whereas the open process does not.
I'd recommend looking into the LaunchServices API. It's what both NSWorkspace and open use behind the scenes, but gives you more control than NSWorkspace's limited API.
--
p.s. If you do have to call out to open (or any other command line tool) from ObjC, you should use Cocoa's NSTask. (AppleScript's do shell script command is just its [crappy] equivalent of NSTask.)

Can you attach a drawer to another application in Cocoa?

Is there a way for one Cocoa application to attach drawer-like windows to another application? We might for example want a terminal drawer that followed around a particular Finder window.
There is a program called DTerm that opens little transparent windows over Finder windows, but one might prefer persistence.
You may want to checkout SIMBL. It allows you to write nifty bundles that are loaded into the application your targeting. If you go along with it I'd reccomend using class dump to gather more information on the application your working with (although Im not sure it would work with Finder)

Question about applescript and expose

Using applescript, how can I get the "preview" of a window of an application? By preview I mean the preview window you see when you use expose on your mac. How can I get those video feeds using applescript, or if not applescript using cocoa framework?
Thanks!
You can't do it from AppleScript, but you can do it from C. See the Quartz Window Services functions and the Son of Grab example.

How do I write custom code upon application quit?

So im trying to figure out how to run custom code when my application quits. Kind of like how I run awakeFromNib when the program starts to initiate certain items, im looking for the program quit equivilant so I can save the user interface state. Thanks.
Zach
UPDATE: Im not programmin in iOS, im trying to write a mac application.
You're looking for applicationWillTerminate, I think.

Hiding a Mac application from the dock

I am trying to create an application with the only purpose to implement a Applescript dictionary, and extend Applescript.
I have read of faceless applications (agents), but my application allows Applescript scripts to show some dialog boxes.
What can I do to avoid my application icon appears in the dock when it is invoked by Applescript?
Agent applications can show dialog boxes if they want to.
The Agent overview here mentions this.
To set it specify LSUIElement as 1 in your info.plist file.