If you open your app in the Finder using control-click and Show Package Contents, you’ll see a Contents folder and a file called Info.plist. Info.plist is an XML file, and you need to edit it. The easiest (and safest) method is to use a property list editor, but unfortunately Apple no long ships one separately from Xcode, and I don’t think any of the others are free.
But if you’re comfortable enough editing XML in a text editor, you just need to add the following:
You can also define you application as an agent so you won’t see it in the dock nor in the main menu bar but you can display objects and show status symbol/menu in the system menu (next to the clock).
Or when you have a property list editor you should add ‘Application is Agent (UIElement)’ field and check it. Now your application is allowed to display a dialog by itself (user interaction allowed).
I’m on a lion machine again and did the following:
Open script editor
Open new template cocoa applescript
The Code:
--create a menu item
set myMenuItem to current application's class "NSMenuItem"'s alloc()'s init()
tell myMenuItem to setTitle_("Hello World")
tell myMenuItem to setTarget_(me)
tell myMenuItem to setAction_("helloWorld:")
--create a menu
set myMenu to current application's class "NSMenu"'s alloc()'s init()
tell myMenu to addItem_(myMenuItem)
set myBar to current application's class "NSStatusBar"'s systemStatusBar()
--add the menu to the system's status bar
set theItem to myBar's statusItemWithLength_(current application's NSVariableStatusItemLength)
tell theItem to setTitle_("MyMenu")
tell theItem to setHighlightMode_(true)
tell theItem to setMenu_(myMenu)
--actions
on helloWorld_(info)
display dialog "Hello World!"
end helloWorld_
Now save the script as an application and check stay-open and other options off
Open the info.plist file inside the application bundle and add the following:
Now double click your application and you see that an menu appears next to the clock, Click the menu item in it and you’ll see a dialog appear.
I know this should be posted in AppleScript-ObjC but I want to show McUsr that it is possible with script editor only.
That depends. The ability to save Cocoa-AS apps from AppleScript Editor was introduced in 10.7, but you can also do it in 10.6 (it’s a bit fiddly – you have to manually edit an existing Cocoa-As app).
Do any of you have a linke to a post describing how to fiddle with it in ASEditor to make it work, the whole process preferably, or the parts from different posts, I have searched, but nothing turns up by reading the headings, and I don’t have the time to do all that reading right now.
A normal AS applet has the script saved as main.scpt in /Contents/Resources/Scripts. The Cocoa-AS apps save your script in the same place, but they also have a script called CocoaAppletAppDelegate.scpt in /Contents/Resources/. If you open the latter, you’ll see that is standard ASObjC script that loads the second script and calls run/open/reopen/quit as on it as required.
If you don’t have Lion I won’t suggest you use Script Editor at all. Use Shane’s AppleScriptObjC Explorer 2 editor which makes everything a lot easier. You can run and edit like normal script editor but also (if you pay a small amount) export to an Application.
EDIT: Another reason not to use SL’s SE is that you can’t use ‘class “”’ command.
Just to clarify: it’s free to try for 30 days (well, actually, longer…), during which there are no limitations. I’ll spare everyone the sales pitch on why it’s so much better
I really don’t mind trying new things. Nor to pay for programming tools that I find useful. But it is also a question of time, and whether I’ll bite over more than I can chew. Summer is soon gone now, and the chores are coming up!
It is also one more thing, everything I use run on batteries, I am really inclined to throw out simbl, and all scripting additions, in fact every unnecessary process, as I love the freedom the battery gives me! But hates the charging time!
I’ll see if I can make this thing running, by making a cocoa applet with XCode, and “fiddling” it!