2442 Views 4 Replies Latest reply: Oct 9, 2009 3:02 PM by Caramby
Very helpful — I added these lines & the application was indeed hidden. Unfortunately, the script (which is running as a droplet app) is batch processing files, & these continue to open new windows (one at a time) which remain visible.
That's much better than what was happening (i.e., constant interruptions!), but it would be even better if the entire batch was processed invisibly. Otherwise it's still a bit distracting.
I tried making the script hidden as well (thinking that perhaps these windows belonged to the script), but it didn't like that since the application is in fact System Events.
Anyway, already this is a massive improvement — so thanks!
When launching apps by AppleScript, how do you keep them in the background, & not take focus away from other apps that may be running at the same time?
That depends on how you launch them.
AppleScript has two direct commands to launch an application in addition to indirect commands which will open an app if it's not already running):
activate -- bring an application frontmost and launch it if it's not already running
launch -- open the application in the background
So you should try using 'launch' instead of 'activate'.
The windows will still be visible, but it will launch behind the frontmost app so you don't lose focus. Note though that some commands (especially System Events and UI scripting commands) require the application to be frontmost so you should look at what you're trying to do once it's open to see if it truly is viable to run in the background.
Very intriguing. I was indeed using 'activate' — & substituting 'launch' (& also removing the 'visible is false' lines again) had exactly the same effect as the first solution.
IOW, each of the two proposed solutions produces the same result; although changing one word is more efficient than adding three lines.
Being entirely new to AppleScript, I had attempted an Automator Workflow first, which did work; but this is better. I think you are probably right, & the Windows do need to be opened, which means they must be visible, which means this may be the best possible solution.
It's slightly distracting having them open every few seconds, but at least now I don't have to keep pressing Command-Tab all the time — which is a bit confusing when you're trying to compose an email or something!