Skip to content

Instantly share code, notes, and snippets.

@uchcode
Last active December 17, 2020 21:10
Show Gist options
  • Save uchcode/f6c163e62a6548f8fc93 to your computer and use it in GitHub Desktop.
Save uchcode/f6c163e62a6548f8fc93 to your computer and use it in GitHub Desktop.
calling osascript from ruby
require "open3"
def osascript language, script
Open3.capture3 "osascript", *["-l", language, :stdin_data => script]
end
def applescript script
osascript "AppleScript", script
end
def jxascript script
osascript "JavaScript", script
end
p applescript <<-END
display alert 1+1
END
p jxascript <<-END
App = Application.currentApplication()
App.includeStandardAdditions = true
App.displayAlert(1+1)
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment