Run another application using AppleScript without showing it on the dock - applescript

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.

Related

AppleScript: How can i hide an applescript-program from the desktop while it is running?

My appleScript-program runs several minutes and I don't wont see the script running. Can I hide it from the desktop a appleScript-command at the beginning of the program
I assume by "AppleScript-program" you mean an AppleScript app: an AppleScript saved as an application to run independently of Script Editor. If that's the case, the you want to set the LSUIElement property of the app to 'true'. There are two ways to do this:
Manually edit the Application's info.plist file
Locate the AppleScript app icon in the Finder
Right-click on the icon and choose "Show Package Contents"
Open the "Contents" folder that appears
Open the "info.plist" file in a plain-text editor (like BBEdit or TextEdit")
Check to make sure there isn't an 'LSUIElement' key in the plist
Add the following key-value pair to the plist, or edit one that's there, without breaking up any other key-value pairs:
<key>LSUIElement</key>
<true/>
Use terminal to set the value
Open Terminal.app (or an equivalent command-line application)
Type in the following command, and execute:
defaults write /Path/to/YourScriptApp.app/Contents/Info LSUIElement 1
Both methods produce the same outcome, so do whichever you're more comfortable with.

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.

Disable "The last time you opened *, it unexpectedly quit while reopening windows" dialog in OSX 10.8

I managed to successfully silence the CrashReport dialog, but when my application crashes and I restart it, I get the annoying dialog as from Title. Is there a way to prevent it to appear, and just let the application run without interruption?
Try this to get rid of the reopening windows:
defaults write -app "Application Name" NSQuitAlwaysKeepsWindows -bool false
You may also disable it for every application by selecting this option in the preferences: "Close windows when quitting an application"
And for others reading this thread, to remove the CrashReport do this:
defaults write com.apple.CrashReporter DialogType none
Also note that in the source of this information they say:
For this to work one needs to check the box, open the program in
question and immediately close it. On the next re-opening it will work
without Resume.
You may also have to delete:
/Users/…/Library/Saved\ Application\ State/org.python.python.savedState/
I was having a similar problem with google chrome and I could solve it by reading the following link:
https://support.google.com/chrome/thread/22716083?hl=en
Drew Z recommends the following solution there which worked for me:
In the Mac menu bar at the top of the screen, click Go.
Select Go to Folder.
Enter ~/Library/Application Support/Google/Chrome/ in the text field, then press Go.
Locate the folder called "Default" in the directory window that opens and rename it as "Backup default."
Try opening Google Chrome again. A new "Default" folder is automatically created as you start using the browser.
Voila! I've just solved this problem by deleting all Unity-related files inside ~Library/Caches folder on my Mac!
For those trying to accomplish this
defaults write -app "Application Name" NSQuitAlwaysKeepsWindows -bool false
with Python, you may get the error Couldn't find an application named "Python"; defaults unchanged.
To solve this, repeat the process to get the "reopen windows?" pop-up again, but do not choose an option in the pop-up – leave it alone for now. Right-click on the Python application's icon on the dock and choose "Show in Finder". Right-click on the application icon within Finder, hold the option key, and click Copy "Python" as pathname". Paste that in as the "Application Name" for the command above and it should work.
You can disable this for a specific Xcode scheme by going to Edit Scheme, choosing the Options tab, and checking the box labeled "Launch application without state restoration."
However, this will only apply when you actually launch the application from Xcode; it won't disable the dialog when launching by double-clicking in Finder, or when launching from the terminal.
(As best I can tell, there no way for AppKit/NSApplication-based apps to do what UIKit apps can do with UIApplicationDelegate's application:shouldRestoreApplicationState: and disable persistent state entirely for the application.)

Running Applescript: WorkFlowServiceRunner will not terminate

I am trying to make a keyboard shortcut to launch terminal in OS X Mountain Lion.
After some research I found out that I can use Automator to achieve this:
http://mac.tutsplus.com/tutorials/tips-shortcuts/how-to-launch-any-app-with-a-keyboard-shortcut/
It works, but I noticed that whenever I launch a terminal using this method, a process called WorkFlowServiceRunner starts and never terminates. To make matters worse when I launch more terminals (or launch different applications using shortcuts, again, through Automator) multiple WorkFlowServiceRunner processes start and quickly eat up the memory.
I've also tried writing my own applescripts but the problem does not go away. This clearly looks like a memory leak. Is this a bug in OS X Automator? Is there a way to write an applescript so that the WorkFlowServiceRunner terminates after doing its job (e.g. launch a terminal)? Automator seems to be the most "native" way of getting this done and I do not want to use any 3rd party apps.
I have noticed this from time to time.
One way around it would be to make your own service apps with a Cocoa-AppleScript Applet.
It is not very hard to do. And I will try and guide you through it. It should only take you a couple of minutes.
Step 1.
Open your Application Applescript Editor. And go to the "File" Menu -> "New from Template" -> Cocoa-AppleScript Applet.app
Step 2,
Paste this code into the new documents.
property NSWorkspace : class "NSWorkspace"
tell current application's NSApp to setServicesProvider_(me)
NSUpdateDynamicServices()
my runAService()
on runAService()
NSWorkspace's sharedWorkspace()'s launchAppWithBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifier_("com.apple.Terminal", current application's NSWorkspaceLaunchDefault, missing value, missing value)
tell me to quit
end runAService
Step 3,
Compile
(click this to compile)
and Save the app.
*Make sure the show startup screen is unchecked in the Save dialogue.
Giving the app a name like LaunchTerminal.app
Step 4,
Click the "Bundle Contents" button on the top right hand side of the document.
This will open the applications contents view.
Click the Action button and then "Reveal in finder" sub menu.
step 5,
In the contents folder that opens in the finder you will see a file name "info.plist"
Open Terminal.app and type and run this code using the path to this file:
BUT make sure you do not include the ".plist" part of the name when entering it in Terminal.app
/usr/bin/defaults write /Users/YourUserNameHere/myServiceApps/LaunchTerminal.app/Contents/Info NSServices -array-add '{NSMenuItem={default="Launch Terminal";}; NSMessage="runAService"; NSSendTypes=();}'
( You can drag n drop the file into terminal to get the posix path string )
The path part looks like this: /Users/YourUserNameHere/myServiceApps/LaunchTerminal.app/Contents/Info
This code should add an array to the plist file which is part of the apps way of broadcasting it has a service.
step 6,
Compile and Save the App again.
Just to make sure it picks up the changes. ( I found I had to do this even though I should not have to)
step 7,
Double click the app to run it for the first time.
The App will quit straight away. But the first run should have broadcast that it has a service that should be registered with the system
step 8,
Open system Preferences and go to Services -> General (section)
And you will see the "Launch Terminal" service.
Set up your short cut as normal.
Hope this helps..
UPDATE :
I noticed that the tell application "Terminal" to activate. Would not open my default Window groups if I had closed them all and quit Terminal before. The normal behaviour if I have done this is for my default window group to open. ( I have two Tabs open at startup each cd'd to a different path).
So I have change the open application to a cocoa way of doing it.
A do shell script with open the/application/path/. will work also.
Try using Butler or QuicKeys. They both have endless "Trial periods."

Have one application execute an action when another application is given a command using AppleScript?

I know nothing about AppleScript, but I wonder if it could make my life easier: is there a way to write an AppleScript that tells Safari / Firefox / Chrome to refresh the current tab when I save a document in another application, say TextWrangler? Essentially, I want to map the Command+S keyboard shortcut to do two things at once in two separate applications.
If that’s not possible, can you script one application so that saving one file executes a command in another window in that same application?
There are different possible approaches to implement this, but the most straightforward would probably be to create a script that executes all steps you need (i.e. save the document and refresh the window) and bind that to the Cmd+S keyboard combo in the triggering application.
What you need for this approach to work, is, in order:
a method to bind a key combo to a script effective only in a specific application. OS X’ Automator Services fit that bill: their scope can be restricted to a single application (select it in the “only in” drop down at the top of the workflow actions), and they can be assigned a shortcut in the Keyboard preference pane of System Preferences.
a way to relay your commands to the applications they target. AppleScript can help you in two different ways, depending on the fact if your applications are scriptable, i.e. if they have a scripting dictionary you can inspect in the AppleScript editor:
if they do, and their terminology includes the saving action for the editor on one side (most scriptable document based apps do so in the form save <document>), the page refreshing for the browser(s) on the other (Chrome has reload <tab>, Safari gets the same result via a JavaScript detour, i.e. do JavaScript "window.location.reload()" in <document> – I don’t use Firefox), you are set.
if they do not, GUI Scripting might help, i.e. simulating a click on the right UI element (menu or toolbar) via tell application "System Events" to tell process <your process> to click item x of menu y.
That script can then be embedded into the Automator workflow (in an “Run AppleScript” action, to be precise).
As you can see, a lot depends on the exact software you are using. if you are new to AppleScript and the above baffles you, I’d suggest spending a bit of time on the AppleScript pages of Mac OS X Automation (where you’ll also find example scripts which will kick start you into things like GUI Scripting).
One final note: as of this writing, sandboxed applications do not honor key combos assigned to them in the Keyboard Preference pane (they do honor global key combos set there – just not those specifically targeting them). This means you cannot, for instance, currently override TextEdit’s Cmd+S shortcut for saving in Lion. As long as your editor is not sandboxed (easily checked in Activity Monitor), you should have no issue with this.
One solution would be to create a folder action to refresh the current tab when a new file is saved in the folder.
on adding folder items to theFolder after receiving theFiles
tell application "Google Chrome"
activate
tell window 1 to tell active tab
set URL to (get URL)
end tell
end tell
end adding folder items to

Resources