module Alfred
Constants
- VERSION
Public Class Methods
front_appid()
click to toggle source
# File lib/alfred.rb, line 136 def front_appid %x{osascript <<__APPLESCRIPT__ id of application (path to frontmost application as text) __APPLESCRIPT__}.chop end
front_appname()
click to toggle source
# File lib/alfred.rb, line 130 def front_appname %x{osascript <<__APPLESCRIPT__ name of application (path to frontmost application as text) __APPLESCRIPT__}.chop end
search(query = "")
click to toggle source
launch alfred with query
# File lib/alfred.rb, line 122 def search(query = "") %x{osascript <<__APPLESCRIPT__ tell application "Alfred 2" search "#{query.gsub('"','\"')}" end tell __APPLESCRIPT__} end
with_friendly_error(alfred_core = nil) { |alfred| ... }
click to toggle source
Default entry point to build alfred workflow with this gem
Example:
class MyHandler < ::Alfred::Handler::Base # ...... end Alfred.with_friendly_error do |alfred| alfred.with_rescue_feedback = true alfred.with_help_feedback = true MyHandler.new(alfred).register end
# File lib/alfred.rb, line 47 def with_friendly_error(alfred_core = nil, &blk) begin if alfred_core.nil? or !alfred_core.is_a?(::Alfred::Core) alfred = Alfred::Core.new end rescue Exception => e log_file = File.expand_path("~/Library/Logs/Alfred-Workflow.log") rescue_feedback = %Q{ <items> <item autocomplete="" uid="Rescue Feedback" valid="no"> <title>Alfred Gem Fail to Initialize.</title> <arg>Alfred::NoBundleIDError: Wrong Bundle ID Test!</arg> <subtitle>Check log #{log_file} for extra debug info.</subtitle> <icon>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns</icon> </item> <item autocomplete="Alfred-Workflow.log" type="file" valid="yes"> <title>Alfred-Workflow.log</title> <arg>#{log_file}</arg> <subtitle>#{log_file}</subtitle> <icon type="fileicon">/Applications/Utilities/Console.app</icon> </item> </items> } puts rescue_feedback File.open(log_file, "a+") do |log| log.puts "Alfred Gem Fail to Initialize.\n #{e.message}" log.puts e.backtrace.join(" \n") log.flush end exit e.status_code end begin yield alfred alfred.start_handler rescue AlfredError => e alfred.ui.error e.message alfred.ui.debug e.backtrace.join("\n") puts alfred.rescue_feedback( :title => "#{e.class}: #{e.message}") if alfred.with_rescue_feedback exit e.status_code rescue Interrupt => e alfred.ui.error "\nQuitting..." alfred.ui.debug e.backtrace.join("\n") puts alfred.rescue_feedback( :title => "Interrupt: #{e.message}") if alfred.with_rescue_feedback exit 1 rescue SystemExit => e puts alfred.rescue_feedback( :title => "SystemExit: #{e.status}") if alfred.with_rescue_feedback alfred.ui.error e.message alfred.ui.debug e.backtrace.join("\n") exit e.status rescue Exception => e alfred.ui.error( "A fatal error has occurred. " \ "You may seek help in the Alfred supporting site, "\ "forum or raise an issue in the bug tracking site.\n" \ " #{e.inspect}\n #{e.backtrace.join(" \n")}\n") puts alfred.rescue_feedback( :title => "Fatal Error!") if alfred.with_rescue_feedback exit(-1) end end
workflow_folder()
click to toggle source
# File lib/alfred.rb, line 116 def workflow_folder Dir.pwd end