Last active
May 24, 2016 16:01
-
-
Save cskeeters/fca453f00d51329546a781a1e36dbd18 to your computer and use it in GitHub Desktop.
Corrected applescript_utils.rb in "Search Safari and Chrome Tabs" Alfred 2 Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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