Module: Alfred
- Defined in:
- lib/alfred.rb,
lib/alfred/ui.rb,
lib/alfred/osx.rb,
lib/alfred/util.rb,
lib/alfred/handler.rb,
lib/alfred/setting.rb,
lib/alfred/version.rb,
lib/alfred/feedback.rb,
lib/alfred/handler/help.rb,
lib/alfred/feedback/item.rb,
lib/alfred/feedback/file_item.rb,
lib/alfred/feedback/webloc_item.rb,
lib/alfred/handler/autocomplete.rb
Defined Under Namespace
Modules: Handler, OSX, Util
Classes: AlfredError, Core, Feedback, InvalidArgument, InvalidFormat, LogUI, NoBundleIDError, NoMethodError, ObjCError, PathError, Setting
Constant Summary
collapse
- VERSION =
'2.0.5'
Class Method Summary
collapse
Class Method Details
.front_appid ⇒ Object
136
137
138
139
140
|
# 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 ⇒ Object
130
131
132
133
134
|
# 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 = "") ⇒ Object
122
123
124
125
126
127
128
|
# 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, &blk) ⇒ Object
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# 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 ⇒ Object
116
117
118
|
# File 'lib/alfred.rb', line 116
def workflow_folder
Dir.pwd
end
|