Passing item to action "action.sh" script with terminal command not working

Sharing and discussing custom actions for LaunchBar
benjaminwil
Posts: 6
Joined: Thu Oct 29, 2015 9:19 pm
Contact:

Passing item to action "action.sh" script with terminal command not working

Postby benjaminwil » Fri Aug 24, 2018 5:39 pm

I'm making a LaunchBar action with Ruby. My default.rb code seems complete, and I can successfully pass an item to another script, which is a Bash script. I have already chmoded it to executable.

The Bash script is simply this:

Code: Select all

#!/bin/sh

result=$1
/usr/local/bin/pass -c $result


The pass -c argument copies a password in my password store to the clipboard for 48 seconds.

I can successfully run this script manually in my terminal (sh pass.sh argument). When I do this, the password is attached to the clipboard.

If I do not pass my default.rb script to the Bash script, the rest of my script runs successfully.

When I run it through LaunchBar, I always am told to see Console for error messages. None of them are very descriptive.

I would be interested in using the LaunchBar JavaScript functions instead of a Bash script, but when I pass my Ruby script to a JavaScript script, a LaunchBar dialog box always tells me "The script is invalid."

Here is my default.rb script for reference:

Code: Select all

#!/usr/bin/env ruby

require 'json'

if `echo $PASSWORD_STORE_DIR` == "\n"
  @password_store_dir = `echo $HOME/.password-store`.strip
else
  @password_store_dir = `echo $PASSWORD_STORE_DIR`.strip
end

def password_store_contents
  contents = `find #{@password_store_dir.to_s} -type f`
  contents.gsub("#{@password_store_dir}/", "").gsub(".gpg", "").split(/\n+/)
end

search_results = Array.new

password_store_contents.each do |item|
  ARGV.each do |search_query|
    search_results.push({
      title: "#{item}",
      action: "pass.sh",
      actionArgument: "#{item}"
    }) if item.include? search_query
  end
end

puts search_results.to_json


I would *super* appreciate *any* help with this, of course. Even if you don't have a full-out solution for me.

If necessary, I will port all my Ruby to JavaScript, too.

Let me know if I can provide any other information.

Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 1 guest