Run an apple script saved as run only so icon doesnt show in dock - applescript

I created an apple script and placed on my desktop. I first saved it as .app and when double clicked it ran code successfully and closed. However in the time it would run it would show an icon in my dock.
So to avoid that i thought lets save it as a run only script. So I did that but now when I double click it, it doesn't run the script, it just says 'it was saved as read only and cannot open'.

You can edit the Contents/Info.plist (easy with Xcode) located in the app bundle and add a Application is agent (UIElement) - Key with value YES to it. Now it shouldn't show in the Dock when running.
The raw text to include is:
<key>LSUIElement</key>
<true/>

Change your run only script's extension from ".scpt" to ".app" and you should be able to run the thing.
More information can be found in this closely related question.

Related

How to create dock icon for running terminal command in Mac OS

Now I open jmeter using terminal using command: open /usr/local/bin/jmeter
I need it frequently, so I want to create dock icon to run this command.
How can I do it?
I tried to make a right click and choose 'keep in dock' option. However, it disappears when I close the application.
The closest I could get was creating a desktop icon through the following method:
Create a plain text document in TextEdit
Paste the following code in the document
#!/bin/bash
open /usr/local/bin/jmeter
Save the file as fileName.command
Open Terminal and navigate to the directory which you saved the file
Type in chmod +x fileName.command and hit enter
You should now have a shortcut to execute this command! I know this isn't the exact solution you were looking for, but I hope this still solves your problem.
Following E. Zimbelman's answer, you create a .command executable file and then
you can add an icon (drag and drop an icon file on the icon of the properties window of the file (Cmd+I))
change the .command extension to .app
so you can add it the the dock (drag and drop), it's ok if the icon has changed temporarily
and then you change it back to .command
With this you can have any script you like in the .command file and have it on mac's dock.
I suggest you have a look at the answer to this question in the apple stackexchange. It pretty much does exactly what you want (although I have no idea what jmeter does).
The answer is, essentially, use automator to run your script, save the automator job as an app (not a workflow), and drag the resulting object to the dock, once you have it working the way you want.
https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
or the wayback machine copy:
https://web.archive.org/web/20160921184459/https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
I needed a simple terminal command to unmount an internal disk which keeps spinning up whilst appearing in Finder to be unmounted. I am running the Mac from an external SSD.
All that was required was to open Script Editor and enter the text:
do shell script "diskutil eject /dev/nameofthedisk"
and then save that as an Application. Drag that to the dock and now I have one click unmounting of the disk when it spins up.

How to remove the dock icon of a shell executable?

I have a java application built with Eclipse, for Mac OS X.
This app is installed via a .pkg file and supposed to be daemonized. Everything works fine, with Macbooks (Pro, Retina), but with the iMac I work on, when the application launches, i have an icon on the Dock, as you can see on the
following link.
I have already tried the solution in this topic: stackoverflow.com/a/620950/3641679 but it didn't work (I still have the Dock icon). Currently the Info.plist looks like this.
What can I do?
Thank you for the time you'll be taking to help me.
Informations (assuming the app name is testapp)
I stop or start the daemon using launchctl start/stop
When I double click on the executable (in testapp.app/Contents/MacOs/testapp) i have the testapp.app in the Dock (with the icon file specified in the Info.plist). Here is a screenshot res.cloudinary.com/doit0eqlo/image/upload/v1400750376/app_k3adzh.png
Sorry for some links, I must have 10 reputation to post more than 2 links.
So, I finally found the solution! The solution is in several steps.
Step 1: Editing the Info.plist
I had to add the LSBackgroundOnly key. It is a string and has to be set to 1.
As said in the Apple Documentation :
LSBackgroundOnly
specifies whether this app runs only in the background. If this key exists and is set to “1”, Launch Services runs the app in the background only.
Information:
Although the documentation specifies this key is a boolean, setting it to a string with the value 1 in it does the trick.
To do so:
Go to your app's folder
Go into the .app's folder then the Contents one (eg. /Applications/test.app/Contents)
Open the Info.plist with any text editor you want (SublimeText, TextEdit,Xcode, etc.)
Add the following lines before the closing dict tag (</dict>)
<key>LSBackgroundOnly</key>
<string>1</string>
Save everything.
Step 2: Edit the appname.ini
Initially I only did the part 1, so it wasn't enough. I found the solution in this question.
The file is in the 'Contents/MacOs' folder inside your application's .app (e.g /Applications/testapp.app/Contents/MacOs/testapp.ini).
Open the .ini file (with any text editor you want).
Before the -vmargs line, add the following line: -nosplash
After the -vmargs line, add the following two lines:
-Xdock:hidden
-Dapple.awt.UIElement=false
Save the file, and now you can launch the app: it shouldn't be any icon neither in the Dock nor in the 'Force Quit' window, but your app should be running in the background.
Hope this helps,
Add this to your info.plist: -
<key>LSUIElement</key>
<true/>
Note that the value here is set to 'true' and not 1
As the Apple docs state: -
Specifies whether the app is an agent app, that is, an app that should not appear in the Dock or Force Quit window. See “LSUIElement” for details.

automatically running wine while double clicking .exe file on mac

I have already had wine on my mac, now I would like to know whether it's possible to automatically running wine when I double-click an .exe file (on Finder), because I believe wine doesn't go to my Application folder when I installed it...
If possible, how exactly?
PS: I don't know if this is needed, I use MacOS Lion.
We can use Apple Script to run the exe file.
Open Script Editor.
Add code below:
tell application "Terminal"
do script "'/Applications/Wine Stable.app/Contents/Resources/wine/bin/wine64'
~/.wine/drive_c/Program\\Files/$PATH_TO_PROGRAM.exe"
end tell
Save as application (not as a script) on the Desktop
Double click to run the application.
This is a question better asked on SuperUser.com, but anyways... if you click "Get Info" on your .exe app within the Finder, one of the items in the Info window that shows up will be "Open with:".
You can select WINE as the app to open those .exe files.

Run another application using AppleScript without showing it on the dock

Using AppleScript you can create a script that runs another application, and then save that script itself as an application and place it in the dock. The problem (not really a problem) is that when you click it, it will still show the other application on the dock. Is it possible to prevent the other application from showing in the dock, yet show its GUI as it would normally do when executed?
Thanks
The only solution I can think of is to actually modify the 'other app' to have no Dock icon. It works, but it's nasty:
•Yep, you're directly modifying the other app—not doing something from your script.
•Accordingly, it will change every launch of said other app, not just invocation from your script.
•It prevents OtherApp from having a menubar (though key combos and any in-window controls will still work).
It's easily reversed though, and can almost always be done just by adding a GUI mode flag to the app's Info.plist file:
Right- or Ctrl-click the other app and Choose 'Show Package Contents'
Open the 'Contents' folder
Open the Info.plist in your text/xml editor of choice*
Add these two lines right after the first line that says <dict>
<key>NSUIElement</key>
<true/>
Save, then fire up the app. Remember… no menubar, so make sure one of its windows has focus and -Q to quit when you verify it runs with no Dock icon.
*If you're squeamish with editing xml, or if the plist file is the binary variety, you'll need a dedicated plist editor. Apple's own Property List Editor is included with their free Dev Tools.
Add a Child to the root ("Information Property List").
Set the name to NSUIElement.
From the Edit (or context) menu, set the Value Type to Boolean.
Click the checkbox ON (sets the bool to true).
Building off the previous answer -- you can modify the Info.plist of your Applescript application with the same XML code. This will prevent the Applescript app from displaying an icon (and having a menubar, which in my experience is unusable anyway for this type of 'app'), but your main application -- the one you're launching from the applescript -- will display in the Dock as usual.
I tried this on OSX 10.7 Lion and it worked successfully.

run applescript on 2x-click

OK, this feels like an idiot question, but I'm stuck - I don't know the first thing about AppleScript. I have a .scpt file and I want to double-click it and just have it run, but instead every time I click, it opens up the AppleScript Editor. This feels like it should just be an option on the file, but I'm missing something obvious.
Please help me feel less dumb, thank you.
From the “File” menu, choose “Export”; there’ll be a “File Format” dropdown underneath the file browser. To get a double-clickable application instead of a document, choose “Application”. This will produce a .app bundle like ordinary Mac applications (this will also let you package other resources with your script if you need to). You can choose “Run Only” or not; if you do, then anybody with just the .app won’t be able to edit your script further, since it’ll be compiled. (But if you’re saving a copy as the application, that might be what you want.)
Another option, as per an anonymous user on Ask Different, would be to save/export your file as a “Script” (.scpt) or “Script Bundle” (.scptd), save it in ~/Library/Scripts/, and check “Show Script menu in menu bar” in Script Editor’s preferences.
(If you’re running an old version of OS X, the first version of this answer has the information you’re looking for.)
There's more than one way to do it; i have found this to be the simplest:
In sum, you create an Automator application and place your applescript inside it (easier than it sounds, and it's not a hack either--there's actually a specific Automator action for this). Then when you are finished, you select "File" from the menubar, next "Save As Application", then select a location. Now check there and you'll see the newly-created Automator icon (little white robot holding a grenade launcher).
You can do anything that you would ordinarily do with this application icon--double click to open, drag it to your dock, etc.
Appstorm has created an excellent step-by-step tutorial for building an applescript-embedded automator action. On the page i linked to, the tutorial author has also supplied an Automator script that you can download and use as a template.
While it's certainly not the simplest route, one benefit to running your script from Automator, as doug suggested, is that you can set a hotkey or keyboard shortcut to execute your script if you hide it in an Automator Service (OSX 10.6+). See:
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
When you save a new script, a menu should appear asking what you want the file name to be, where it will be stored, any tags for it, and what script format you want it to be. There should be 4 scripts formats:
Script
Script Bundle
Application
Text
The script format you want to use would be "Application." This will turn it into a double-click application if its not in the dock.

Resources