Class: NSRunningApplication

Inherits:
Object show all
Defined in:
ext/accessibility/extras/extras.c,
ext/accessibility/extras/extras.c

Overview

A 99% drop-in replacement for Cocoa's NSWorkspace class on MRI and other non-MacRuby rubies.

See Apple's Developer Reference for documentation on the methods in this class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentApplication ⇒ Object



75
76
77
78
79
80
81
82
# File 'ext/accessibility/extras/extras.c', line 75

static
VALUE
rb_running_app_current_app(VALUE self)
{
    NSRunningApplication* const app = [NSRunningApplication currentApplication];
    if (app) return wrap_app(app);
    return Qnil;
}

.runningApplicationsWithBundleIdentifier(bundle_id) ⇒ Object

ruby behaviour would be to raise, but we want "drop-in" compat



67
68
69
70
71
72
73
# File 'ext/accessibility/extras/extras.c', line 67

static
VALUE
rb_running_app_with_bundle_id(VALUE self, VALUE bundle_id)
{
  return wrap_array_apps([NSRunningApplication
			  runningApplicationsWithBundleIdentifier:unwrap_nsstring(bundle_id)]);
}

.runningApplicationWithProcessIdentifier(num_pid) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'ext/accessibility/extras/extras.c', line 55

static
VALUE
rb_running_app_with_pid(VALUE self, VALUE num_pid)
{
    const pid_t pid = NUM2PIDT(num_pid);
    NSRunningApplication* const app =
      [NSRunningApplication runningApplicationWithProcessIdentifier:pid];

    if (app) return wrap_app(app);
    return Qnil; // ruby behaviour would be to raise, but we want "drop-in" compat
}

.terminateAutomaticallyTerminableApplications ⇒ Object



84
85
86
87
88
89
90
# File 'ext/accessibility/extras/extras.c', line 84

static
VALUE
rb_running_app_drop_nuke(VALUE self)
{
  [NSRunningApplication terminateAutomaticallyTerminableApplications];
  return rb_cRunningApp; // return this to be MacRuby compatible
}

Instance Method Details

#==(other) ⇒ Object



232
233
234
235
236
237
238
239
240
# File 'ext/accessibility/extras/extras.c', line 232

static
VALUE
rb_running_app_equality(VALUE self, VALUE other)
{
  if (CLASS_OF(other) == rb_cRunningApp)
    if ([unwrap_app(self) isEqual:unwrap_app(other)])
      return Qtrue;
  return Qfalse;
}

#activateWithOptions(options) ⇒ Object



100
101
102
103
104
105
# File 'ext/accessibility/extras/extras.c', line 100

static
VALUE
rb_running_app_activate(VALUE self, VALUE options)
{
  return ([unwrap_app(self) activateWithOptions:FIX2INT(options)] ? Qtrue : Qfalse);
}

#activationPolicy ⇒ Object



107
108
109
110
111
112
# File 'ext/accessibility/extras/extras.c', line 107

static
VALUE
rb_running_app_activation_policy(VALUE self)
{
  return INT2FIX(unwrap_app(self).activationPolicy);
}

#active? ⇒ Boolean

return this to be MacRuby compatible

Returns:

  • (Boolean)


93
94
95
96
97
98
# File 'ext/accessibility/extras/extras.c', line 93

static
VALUE
rb_running_app_is_active(VALUE self)
{
  return unwrap_app(self).isActive ? Qtrue : Qfalse;
}

#bundleIdentifier ⇒ Object

rb_define_method(rb_cRunningApp, "icon", rb_running_app_icon, 0);



147
148
149
150
151
152
153
154
155
# File 'ext/accessibility/extras/extras.c', line 147

static
VALUE
rb_running_app_bundle_id(VALUE self)
{
  NSString* name = [unwrap_app(self) bundleIdentifier];
  if (name)
    return wrap_nsstring(name);
  return Qnil;
}

#bundleURL ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
# File 'ext/accessibility/extras/extras.c', line 157

static
VALUE
rb_running_app_bundle_url(VALUE self)
{
  NSURL* url  = [unwrap_app(self) bundleURL];
  VALUE rburl = Qnil;
  if (url)
    rburl = wrap_nsurl(url);
  [url release];
  return rburl;
}

#executableArchitecture ⇒ Object



169
170
171
172
173
174
# File 'ext/accessibility/extras/extras.c', line 169

static
VALUE
rb_running_app_executable_arch(VALUE self)
{
  return INT2FIX(unwrap_app(self).executableArchitecture);
}

#executableURL ⇒ Object



176
177
178
179
180
181
# File 'ext/accessibility/extras/extras.c', line 176

static
VALUE
rb_running_app_executable_url(VALUE self)
{
  return wrap_nsurl(unwrap_app(self).executableURL);
}

#finishedLaunching? ⇒ Boolean

Returns:

  • (Boolean)


190
191
192
193
194
195
# File 'ext/accessibility/extras/extras.c', line 190

static
VALUE
rb_running_app_is_launched(VALUE self)
{
  return (unwrap_app(self).isFinishedLaunching ? Qtrue : Qfalse);
}

#forceTerminate ⇒ Object



211
212
213
214
215
216
# File 'ext/accessibility/extras/extras.c', line 211

static
VALUE
rb_running_app_force_terminate(VALUE self)
{
  return ([unwrap_app(self) forceTerminate] ? Qtrue : Qfalse);
}

#hidden? ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
131
132
133
# File 'ext/accessibility/extras/extras.c', line 128

static
VALUE
rb_running_app_is_hidden(VALUE self)
{
  return (unwrap_app(self).isHidden ? Qtrue : Qfalse);
}

#hide ⇒ Object



114
115
116
117
118
119
# File 'ext/accessibility/extras/extras.c', line 114

static
VALUE
rb_running_app_hide(VALUE self)
{
  return ([unwrap_app(self) hide] ? Qtrue : Qfalse);
}

#launchDate ⇒ Object



183
184
185
186
187
188
# File 'ext/accessibility/extras/extras.c', line 183

static
VALUE
rb_running_app_launch_date(VALUE self)
{
  return wrap_nsdate(unwrap_app(self).launchDate);
}

#localizedName ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
# File 'ext/accessibility/extras/extras.c', line 135

static
VALUE
rb_running_app_localized_name(VALUE self)
{
  NSString* string = [unwrap_app(self) localizedName];
  VALUE        str = Qnil;
  if (string)
    str = wrap_nsstring(string);
  [string release];
  return str;
}

#ownsMenuBar ⇒ Object Also known as: ownsMenuBar?



204
205
206
207
208
209
# File 'ext/accessibility/extras/extras.c', line 204

static
VALUE
rb_running_app_owns_menu_bar(VALUE self)
{
  return (unwrap_app(self).ownsMenuBar ? Qtrue : Qfalse);
}

#processIdentifier ⇒ Object



197
198
199
200
201
202
# File 'ext/accessibility/extras/extras.c', line 197

static
VALUE
rb_running_app_pid(VALUE self)
{
  return PIDT2NUM(unwrap_app(self).processIdentifier);
}

#terminate ⇒ Object



218
219
220
221
222
223
# File 'ext/accessibility/extras/extras.c', line 218

static
VALUE
rb_running_app_terminate(VALUE self)
{
  return ([unwrap_app(self) terminate] ? Qtrue : Qfalse);
}

#terminated? ⇒ Boolean

Returns:

  • (Boolean)


225
226
227
228
229
230
# File 'ext/accessibility/extras/extras.c', line 225

static
VALUE
rb_running_app_is_terminated(VALUE self)
{
  return (unwrap_app(self).isTerminated ? Qtrue : Qfalse);
}

#unhide ⇒ Object



121
122
123
124
125
126
# File 'ext/accessibility/extras/extras.c', line 121

static
VALUE
rb_running_app_unhide(VALUE self)
{
  return ([unwrap_app(self) unhide] ? Qtrue : Qfalse);
}