Run Script as App Without Menu Bar?

Hey,

I’m running a simple script:

set screenShotFile to (path to desktop as text) & “screenshot.pdf”

do shell script "screencapture -tpdf " & quoted form of POSIX path of screenShotFile

that when i run it as an app always displays a menu bar showing the name of the app
which of course rather ruins the screen capture.

Anyway to not have the menu bar show?

Thanks,

Carl

You need to go into the application’s bundle and change it’s Info.plist file to include an entry for LSBackgroundOnly, with a value of 1.

Thanks, not familiar with that technique. Maybe an example?

Carl

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:

	<key>LSBackgroundOnly</key>
	<true/>

Excellent, thanks a bunch Shane.

Carl

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).

Hello DJ!

How do you do that, care to share? :smiley:

In the info.plist you should contain

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).

Good!

But is there any way I can get my script into the menubar, or, how do I define such an item? :slight_smile:

I have suspicion about defining a folder structure somewhere, may give me a menu at the menubar.
And that! Would be nice! :smiley:

Not with pure AppleScript, unless you mean the script menu.
You need Xcode with AppleScriptObjC or ObjC

I see!

But is there any way I can just make a menu appear by a folder structure put somewhere?

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.

:slight_smile:

Hmmm.that looks interesting! …I think I’ll start hanging in the AsObj-C section :smiley:

I actually used DatabaseEvents in combination with an AppleScript Studio app a while ago. It is about time to tinker with AsObj!

:frowning: I must upgrade from SL it seems!

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).

Hello and thanks!

I’ll have a look into it, when I hopefully have slept :slight_smile:

Hello!

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.

Thanks

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 :slight_smile:

Hello!

Thanks a whole lot!

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! :frowning:

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! :smiley: 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! :slight_smile: