Class: Appear::MacOs
- Inherits:
-
Service
- Object
- BaseService
- Service
- Appear::MacOs
- Defined in:
- lib/appear/mac_os.rb
Overview
The MacOs service handles macOS-specific concerns; mostly running our companion macOS helper tool.
Constant Summary collapse
- SCRIPT =
the “realpath” part is basically an assertion that this file exists.
Appear::TOOLS_DIR.join('macOS-helper.js').realpath.to_s
Instance Method Summary collapse
-
#call_method(method_name, data = nil) ⇒ Any
call a method in our helper script.
-
#has_gui?(process) ⇒ Boolean
Return true if the given process is a macOS GUI process, false otherwise.
Methods inherited from BaseService
delegate, #initialize, require_service, required_services
Constructor Details
This class inherits a constructor from Appear::BaseService
Instance Method Details
#call_method(method_name, data = nil) ⇒ Any
call a method in our helper script. Communicates with JSON!
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/appear/mac_os.rb', line 27 def call_method(method_name, data = nil) command = [SCRIPT, method_name.to_s] command << data.to_json unless data.nil? output = run(command) result = JSON.load(output.lines.last.strip) if result["status"] == "error" raise MacToolError.new(result["error"]["message"], result["error"]["stack"]) else result["value"] end end |
#has_gui?(process) ⇒ Boolean
Return true if the given process is a macOS GUI process, false otherwise.
@todo: ask Applescript if this a GUI application instead of just looking
at the path
47 48 49 50 |
# File 'lib/appear/mac_os.rb', line 47 def has_gui?(process) executable = process.command.first executable =~ /\.app\/Contents\// end |