Jump to content

Passing Alfred variables into a shell script and running it in the background

Recommended Posts


I'm a complete noob in regards to Alfred workflows, but I wanted to try and do something to experiment. 

I have a CLI app that runs a scan on files in a folder and produces a log with the results. The cli app takes one argument - a folder name. 

What I'm doing now is

/.mqi "path/to/folder" > "path/to/the/same/folder/mqi.log"


So what I would like to do is navigate to a required folder in Path Finder and invoke Alfred and type `mqi` to both run that CLI app on that folder AND generate a log file in that folder.


I looked at several examples and hacked this:


on alfred_script(q)
  tell application "Path Finder"
    set pathList to POSIX path of the target of the front finder window
    set pathList to quoted form of pathList
    set command to "/Users/user_name/.cliapps/./MQI " & pathList & " > " & pathList & "/mqi.log"
  end tell
  tell application "System Events"
    -- some versions might identify as "iTerm2" instead of "iTerm"
    set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
  end tell
  tell application "iTerm"
    set hasNoWindows to ((count of windows) is 0)
    if isRunning and hasNoWindows then
      create window with default profile
    end if
    select first window
    tell the first window
      if isRunning and hasNoWindows is false then
        create tab with default profile
      end if
      tell current session to write text command
    end tell
  end tell

end alfred_script


It works but of course the ideal solution would be to run the task in the background without even opening the terminal.


Are there any pointers how I could proceed with this? 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...