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

.currentApplicationObject



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

static
VALUE
rb_running_app_current_app(VALUE self)
{
  NSRunningApplication* 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



73
74
75
76
77
78
79
# File 'ext/accessibility/extras/extras.c', line 73

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

.runningApplicationWithProcessIdentifier(pid) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'ext/accessibility/extras/extras.c', line 62

static
VALUE
rb_running_app_with_pid(VALUE self, VALUE pid)
{
  NSRunningApplication* app = [NSRunningApplication
			       runningApplicationWithProcessIdentifier:NUM2PIDT(pid)];
  if (app)
    return wrap_app(app);
  return Qnil; // ruby behaviour would be to raise, but we want "drop-in" compat
}

.terminateAutomaticallyTerminableApplicationsObject



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

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



239
240
241
242
243
244
245
246
247
# File 'ext/accessibility/extras/extras.c', line 239

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



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

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

#activationPolicyObject



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

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)


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

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

#bundleIdentifierObject

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



154
155
156
157
158
159
160
161
162
# File 'ext/accessibility/extras/extras.c', line 154

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

#bundleURLObject



164
165
166
167
168
169
170
171
172
173
174
# File 'ext/accessibility/extras/extras.c', line 164

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;
}

#executableArchitectureObject



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

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

#executableURLObject



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

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

#finishedLaunching?Boolean

Returns:

  • (Boolean)


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

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

#forceTerminateObject



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

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

#hidden?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
140
# File 'ext/accessibility/extras/extras.c', line 135

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

#hideObject



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

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

#launchDateObject



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

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

#localizedNameObject



142
143
144
145
146
147
148
149
150
151
152
# File 'ext/accessibility/extras/extras.c', line 142

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;
}

#ownsMenuBarObject Also known as: ownsMenuBar?



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

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

#processIdentifierObject



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

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

#terminateObject



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

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

#terminated?Boolean

Returns:

  • (Boolean)


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

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

#unhideObject



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

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