Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: How to launch-and-hide via AppleScript in 10.5 System 10.5
Under Leopard, the act of launching and hiding apps through AppleScript does not work well (for me anyway!). I have found a simple yet effective way around it that works; I've found that by doubling the commands to activate the individual apps, and also hiding them one by one, they respond better to then being hidden. Here's an example:
tell application "Things" to activate
tell application "Things" to activate
tell application "Finder"
    set visible of process "Things" to false
end tell
tell application "Mail" to activate
tell application "Mail" to activate
tell application "Finder"
    set visible of process "Mail" to false
end tell
In my testing, using only one activate entry fails consistently, and doubling them works every time. This also works for the problematic 'Mail not hiding properly at launch time' bug. I know of the application LaunchandHideMail, but it's nice to have it a bit simpler, and in a form such that other launched items can be added.
    •    
  • Currently 1.80 / 5
  You rated: 1 / 5 (10 votes cast)
 
[30,383 views]  

10.5: How to launch-and-hide via AppleScript in 10.5 | 20 comments | Create New Account
Click here to return to the '10.5: How to launch-and-hide via AppleScript in 10.5' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: diamondsw on Jan 29, '09 08:05:17AM

Strange bugs you're seeing; I'm not seeing anything like that. A single activate works fine for launching, and hide works as expected. The following Works For Me:

tell application "Mail" to activate
tell application "Finder" to set visible of process "Mail" to false



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: francola on Jan 29, '09 08:34:55AM

I am honestly not sure why the normal situation is not working for me. What I posted does work for me though, and it also works with the known issue of Mail not hiding properly as I stated. Anyone's input as to why this might be needed for my machine and not someone else's would be appreciated. I tried disabling spaces to no avail.



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: lrivers on Jan 29, '09 08:39:14AM
I haven't seen the problem you're describing either and I have a pretty large "Launch" script so I can quit my login apps and relaunch them without logging out and in again. What I did instead was have all the activates in a row, then all the hides in a row:
tell application "Finder"

	try
		tell application "Mail"
			activate
		end tell

	try
		tell application "Finder"
			set the visible of process "Mail" to false
		end tell
	
end tell


[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: francola on Jan 29, '09 08:53:34AM

It is very frustrating to be getting different results. Oh well. Does the trick work for anyone as far as the LaunchandHideMail issue?



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: francola on Jan 29, '09 09:02:59AM

Well given the 5 star rating so far, I hope it helped somebody. :)



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: GrandMauvaisDan on Jan 29, '09 09:11:57AM
I just did some quick testing and found that if Mail is not already open you need a delay between
tell application "Mail" to activate
and
tell application "Finder" to set visible of process "Mail" to false
Otherwise, Finder tries to set it hidden before Mail finishes launching. The second activate command just happens to take enough time to serve as the needed delay.

[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: francola on Jan 29, '09 09:30:07AM

OK, good. That was exactly what I found therefore the reason for creating 2 activates in a row. Is there another way to properly send a delay command?

Thanks!



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: GrandMauvaisDan on Jan 29, '09 09:45:34AM
delay some_number
delays for some_number of seconds. So for me the following appears to work fine:
tell application "Mail" to activate
delay 0.5
tell application "Finder" to set visible of process "Mail" to false


[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: ptone on Jan 29, '09 10:45:02AM

delay 5

this will tell the applescript to pause for 5 seconds

decimals are OK, so you could try 3.5

this will be machine specific based on how fast mail launches on your machine



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: trosberg on Jan 31, '09 04:43:55AM
To make sure a launching app is ready to accept input (like visible property), I scripted the app to return a user interface element. I believe this is the minimum delay the app needs.
tell application "iTunes"
	try -- We don't need error messages
		get window 1 -- "tell application" goes on until the app has a user interface, or returns an error.
	end try
end tell

tell application "System Events" -- It is better than the Finder.
	set visible of process "iTunes" to false
end tell


[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: brentb on Jan 29, '09 11:14:17AM
See if this works for you.
tell application "Things" to launch

tell application "Finder" to set vis to the visible of process "Things"

repeat until vis is false
	tell application "Finder"
		set visible of process "Things" to false
		set vis to the visible of process "Things"
	end tell
end repeat


[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: francola on Jan 29, '09 11:50:17AM

No, with that script Things launches and then stays visible, but not in focus. Using delay instead of doubling the activate request works great though. I had to make the delay different for my MacBook and my Mac Mini though due to processor differences.

Thanks everyone for your contributions!



[ Reply to This | # ]
do shell script?
Authored by: awado on Jan 30, '09 10:53:37AM

I have a similar problem. I wanted a fast and simple way to switch on my favorite radio station in iTunes, even if iTunes is not running. Wrote an applescript that choses the playlist and stream, but doesn't show the minimized window. It stays hidden. The following line at the very end of the script did the trick:

do shell script "open /Applications/iTunes.app"



[ Reply to This | # ]
do shell script?
Authored by: trosberg on Jan 31, '09 03:36:12AM

Why not just "activate" as last command in "tell iTunes" block?



[ Reply to This | # ]
do shell script?
Authored by: trosberg on Jan 31, '09 04:12:46AM
Now I think I understand your aim.
To toggle to the small user controls window in iTunes:
tell application "iTunes"
	activate
	tell application "System Events" to keystroke "z" using {command down, control down}
end tell
To make this toggle work, you must have "Enable access to assistive devices" on, in System Preferences, in Universal Access.

[ Reply to This | # ]
do shell script?
Authored by: awado on Jan 31, '09 10:22:39AM
Did you try it? It doesn't show the iTunes Window. I tried various commands. The only one that works is:

tell application "iTunes"
	(...)
	set minimized of front window to true
end tell
do shell script "open /Applications/iTunes.app"


[ Reply to This | # ]
do shell script?
Authored by: trosberg on Feb 03, '09 11:40:14AM

I did try it. And now, after trying your code submitted above, it seems you were after what I thought. Have luck.



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: Anonymous on Feb 10, '09 12:58:17AM
I'm using the same thing by using a loop in an array of app.
The delay 2 is to be sure the app has been loaded sucessfully. If i don't use delay 2, Mail or NNW won't be hide.

set theArray to {"NetNewsWire", "Terminal", "Mail", "TextMate", "Address Book", "iCal"}
repeat with ell in theArray
tell application ell to activate
delay 2
tell application "Finder"
set visible of process ell to false
end tell
end repeat



[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: paulskinner on Feb 10, '09 11:56:41AM
If I follow properly, this should be quicker and not require you to subsequently hide the apps you launch.

The key is Launching them rather than activating them. Activate calls launch and then makes the app frontmost. Launch alone does a nice quiet launch.

set appList to {"Terminal", "Mail", "Address Book", "iCal"}

repeat with thisApplication in the appList
	try
		ignoring application responses
			tell application thisApplication to launch
		end ignoring
	end try
end repeat
     

[ Reply to This | # ]
10.5: How to launch-and-hide via AppleScript in 10.5
Authored by: jadar1 on Jul 06, '12 08:15:03AM

Adding a delay 0.1 is better, but depeing on your Mac's speed for loading up the app you might have to change it..



[ Reply to This | # ]