Hazel launch application?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hazel launch application? Thu Nov 30, 2017 7:35 pm • by staze
Hi All,

Just curious. I have another program watching a folder called iFlicks. Problem is, it doesn't watch the folder when it's not running. Is it possible to just get hazel to launch iFlicks when something is placed in iFlicks' watch folder?

Thanks!
staze
 
Posts: 16
Joined: Sat Feb 28, 2015 5:52 pm

Re: Hazel launch application? Fri Dec 01, 2017 11:40 am • by Mr_Noodle
You'll need a script. Here's a sample AppleScript that should do it:
Code: Select all
tell application "iFlicks" to activate
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Hazel launch application? Fri Dec 01, 2017 1:13 pm • by staze
Mr_Noodle wrote:You'll need a script. Here's a sample AppleScript that should do it:
Code: Select all
tell application "iFlicks" to activate

awesome, thanks!
staze
 
Posts: 16
Joined: Sat Feb 28, 2015 5:52 pm

Re: Hazel launch application? Wed Apr 24, 2019 11:02 am • by Mike678
Mr_Noodle wrote:You'll need a script. Here's a sample AppleScript that should do it:
Code: Select all
tell application "iFlicks" to activate



Found this old post and was wondering if it's possible to have the program launch IF it's not already open. My issue is that I have it set to check if a folder has been modified in the last 10 minutes and launch the program if true... but if the program is already running, then it will bring the program into focus when I am not expecting it to.
Mike678
 
Posts: 4
Joined: Mon Feb 19, 2018 12:24 pm

Re: Hazel launch application? Thu Apr 25, 2019 5:14 am • by Robert
I did not check it in Hazel, but in the script-editor it works. Try the following script and put the name of the app you desire to open if it is not open instead of YOUR APP NAME:

Code: Select all
on is_running(appName)
   tell application "System Events" to (name of processes) contains appName
end is_running

set safRunning to is_running("YOUR APP NAME")
if safRunning then
   
else
   tell application "YOUR APP NAME" to activate
end if


EDIT: Or this script is more compact and should work too I think:

Code: Select all
set appName to "YOUR APP NAME"

if application appName is running then
   return "Already Running"
else
   tell application "YOUR APP NAME" to activate
end if
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Robert
 
Posts: 52
Joined: Sun Dec 16, 2018 8:05 am

Re: Hazel launch application? Sun Jun 02, 2019 5:48 am • by jrpsupport
can we close an application too?
perhps with auto save [but this is not important]
I'm looking to run a sync at weekends FYI :-)
cheers
jrpsupport
 
Posts: 1
Joined: Sun Jun 02, 2019 5:45 am

Re: Hazel launch application? Mon Jun 03, 2019 7:43 pm • by luomat
An alternative to AppleScript is to use the `open` command:

/usr/bin/open -g -j -a iFlicks

From `man open`:

-g Do not bring the application to the foreground.

-j Launches the app hidden.

That will keep the app from stealing focus.
luomat
 
Posts: 78
Joined: Wed Mar 10, 2010 3:57 pm

Re: Hazel launch application? Mon Jun 03, 2019 7:48 pm • by luomat
jrpsupport wrote:can we close an application too?
perhps with auto save [but this is not important]


You mean quit the application?

Assuming you could find the correct criteria, you could use AppleScript to quit the app:

tell application "iFlicks" to quit

or in a shell script:

osascript -e 'tell application "iFlicks" to quit'

jrpsupport wrote:I'm looking to run a sync at weekends FYI :-)


So you only want to run the script on weekends?

I don't think Hazel can do that.
luomat
 
Posts: 78
Joined: Wed Mar 10, 2010 3:57 pm

Re: Hazel launch application? Tue Jun 04, 2019 10:54 am • by Mr_Noodle
You can use the "Current time" attribute to have a rule only match at certain times, including only on weekends.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron