Page 1 of 1

Hazel launch application?

PostPosted: 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!

Re: Hazel launch application?

PostPosted: 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

Re: Hazel launch application?

PostPosted: 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!

Re: Hazel launch application?

PostPosted: 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.

Re: Hazel launch application?

PostPosted: 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

Re: Hazel launch application?

PostPosted: 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

Re: Hazel launch application?

PostPosted: 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.

Re: Hazel launch application?

PostPosted: 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.

Re: Hazel launch application?

PostPosted: 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.