Module: FindApp
- Defined in:
- lib/_aem/findapp.rb
Overview
rb-appscript
findapp – locate an application by name, bundle ID or creator code
Defined Under Namespace
Classes: ApplicationNotFoundError
Class Method Summary collapse
- ._find_app(creator, id, name) ⇒ Object
- .by_creator(creator) ⇒ Object
- .by_id(id) ⇒ Object
- .by_name(name) ⇒ Object
Class Method Details
._find_app(creator, id, name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/_aem/findapp.rb', line 24 def FindApp._find_app(creator, id, name) begin return AE.find_application(creator, id, name) rescue AE::MacOSError => err if err.to_i == -10814 ident = [creator, id, name].compact.to_s.inspect raise ApplicationNotFoundError.new(creator, id, name), "Application #{ident} not found." else raise end end end |
.by_creator(creator) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/_aem/findapp.rb', line 77 def FindApp.by_creator(creator) # Find the application with the given creator type and return its full path. # # Examples: # FindApp.by_creator('ttxt') # return _find_app(creator, nil, nil) end |
.by_id(id) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/_aem/findapp.rb', line 68 def FindApp.by_id(id) # Find the application with the given bundle id and return its full path. # # Examples: # FindApp.by_id('com.apple.textedit') # return _find_app(nil, id, nil) end |
.by_name(name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/_aem/findapp.rb', line 39 def FindApp.by_name(name) # Find the application with the given name and return its full path. # # Absolute paths are also accepted. An '.app' suffix is optional. # # Examples: # FindApp.by_name('TextEdit') # FindApp.by_name('Finder.app') # if name[0, 1] != '/' # application name only, not its full path begin new_name = _find_app(nil, nil, name) rescue ApplicationNotFoundError if ('----' + name)[-4, 4].downcase == '.app' raise ApplicationNotFoundError.new(nil, nil, name), "Application #{name.inspect} not found." end new_name = _find_app(nil, nil, name + '.app') end name = new_name end if not FileTest.exist?(name) and name[-4, 4].downcase != '.app' and not FileTest.exist?(name+ '.app') name += '.app' end if not FileTest.exist?(name) raise ApplicationNotFoundError.new(nil, nil, name), "Application #{name.inspect} not found." end return name end |