Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Corrected applescript_utils.rb in "Search Safari and Chrome Tabs" Alfred 2 Workflow
module BrowserTabs
module AppleScriptUtils
class AppleScriptError < StandardError; end
class << self
def run_file(filename, *args)
osascript(true, *args)
end
def run(src, *args)
osascript(false, src, *args)
end
def escape_str(str)
str.gsub("\\", "\\\\\\").gsub('"', '\\\\"')
end
private
def osascript(is_file, *args)
require 'open3'
src = args.shift unless is_file
Open3.popen3('osascript', *args) do |stdin, stdout, stderr, thr|
stdin.write(src) unless is_file
stdin.close
if thr.value != 0
err_msg = stderr.read.chomp
raise AppleScriptError, "AppleScript error: #{err_msg}"
end
stdout.read.chomp
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.