我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用AppKit.NSWorkspace.sharedWorkspace()。
def reveal_file(self, sender): workspace = NSWorkspace.sharedWorkspace() workspace.selectFile_inFileViewerRootedAtPath_(self.filepath, os.path.dirname(self.filepath))
def filepath(self, value): self._filepath = value selected = value is not None and value is not '' icon = NSWorkspace.sharedWorkspace().iconForFile_(self._filepath) self.choose_file_button.show(not selected) self.remove_file_button.show(selected) self.filepath_label.show(selected) self.filepath_label.set(self.filename) self.filepath_button.show(selected) self.filetype_image.show(selected) self.filetype_image.setImage(imageObject=icon)
def get_running_apps(): """Return a list of running applications""" procs = [] workspace = NSWorkspace.sharedWorkspace() running_apps = workspace.runningApplications() for app in running_apps: procs.append(app.localizedName()) return procs
def install_notifier(): """Extract `Notify.app` from the workflow to data directory. Changes the bundle ID of the installed app and gives it the workflow's icon. """ archive = os.path.join(os.path.dirname(__file__), 'Notify.tgz') destdir = wf().datadir app_path = os.path.join(destdir, 'Notify.app') n = notifier_program() log().debug("Installing Notify.app to %r ...", destdir) # z = zipfile.ZipFile(archive, 'r') # z.extractall(destdir) tgz = tarfile.open(archive, 'r:gz') tgz.extractall(destdir) assert os.path.exists(n), ( "Notify.app could not be installed in {0!r}.".format(destdir)) # Replace applet icon icon = notifier_icon_path() workflow_icon = wf().workflowfile('icon.png') if os.path.exists(icon): os.unlink(icon) png_to_icns(workflow_icon, icon) # Set file icon # PyObjC isn't available for 2.6, so this is 2.7 only. Actually, # none of this code will "work" on pre-10.8 systems. Let it run # until I figure out a better way of excluding this module # from coverage in py2.6. if sys.version_info >= (2, 7): # pragma: no cover from AppKit import NSWorkspace, NSImage ws = NSWorkspace.sharedWorkspace() img = NSImage.alloc().init() img.initWithContentsOfFile_(icon) ws.setIcon_forFile_options_(img, app_path, 0) # Change bundle ID of installed app ip_path = os.path.join(app_path, 'Contents/Info.plist') bundle_id = '{0}.{1}'.format(wf().bundleid, uuid.uuid4().hex) data = plistlib.readPlist(ip_path) log().debug('Changing bundle ID to {0!r}'.format(bundle_id)) data['CFBundleIdentifier'] = bundle_id plistlib.writePlist(data, ip_path)
def install_notifier(): """Extract ``Notify.app`` from the workflow to data directory. Changes the bundle ID of the installed app and gives it the workflow's icon. """ archive = os.path.join(os.path.dirname(__file__), 'Notify.tgz') destdir = wf().datadir app_path = os.path.join(destdir, 'Notify.app') n = notifier_program() log().debug('installing Notify.app to %r ...', destdir) # z = zipfile.ZipFile(archive, 'r') # z.extractall(destdir) tgz = tarfile.open(archive, 'r:gz') tgz.extractall(destdir) assert os.path.exists(n), \ 'Notify.app could not be installed in %s' % destdir # Replace applet icon icon = notifier_icon_path() workflow_icon = wf().workflowfile('icon.png') if os.path.exists(icon): os.unlink(icon) png_to_icns(workflow_icon, icon) # Set file icon # PyObjC isn't available for 2.6, so this is 2.7 only. Actually, # none of this code will "work" on pre-10.8 systems. Let it run # until I figure out a better way of excluding this module # from coverage in py2.6. if sys.version_info >= (2, 7): # pragma: no cover from AppKit import NSWorkspace, NSImage ws = NSWorkspace.sharedWorkspace() img = NSImage.alloc().init() img.initWithContentsOfFile_(icon) ws.setIcon_forFile_options_(img, app_path, 0) # Change bundle ID of installed app ip_path = os.path.join(app_path, 'Contents/Info.plist') bundle_id = '{0}.{1}'.format(wf().bundleid, uuid.uuid4().hex) data = plistlib.readPlist(ip_path) log().debug('changing bundle ID to %r', bundle_id) data['CFBundleIdentifier'] = bundle_id plistlib.writePlist(data, ip_path)
def install_notifier(): """Extract `Notify.app` from the workflow to data directory. Changes the bundle ID of the installed app and gives it the workflow's icon. """ archive = os.path.join(os.path.dirname(__file__), 'Notify.tgz') destdir = wf().datadir app_path = os.path.join(destdir, 'Notify.app') n = notifier_program() log().debug("Installing Notify.app to %r ...", destdir) # z = zipfile.ZipFile(archive, 'r') # z.extractall(destdir) tgz = tarfile.open(archive, 'r:gz') tgz.extractall(destdir) assert os.path.exists(n), ( "Notify.app could not be installed in {0!r}.".format(destdir)) # Replace applet icon icon = notifier_icon_path() workflow_icon = wf().workflowfile('icon.png') if os.path.exists(icon): os.unlink(icon) png_to_icns(workflow_icon, icon) # Set file icon # PyObjC isn't available for 2.6, so this is 2.7 only. Actually, # none of this code will "work" on pre-10.8 systems. Let it run # until I figure out a better way of excluding this module # from coverage in py2.6. if sys.version_info >= (2, 7): # pragma: nocover from AppKit import NSWorkspace, NSImage ws = NSWorkspace.sharedWorkspace() img = NSImage.alloc().init() img.initWithContentsOfFile_(icon) ws.setIcon_forFile_options_(img, app_path, 0) # Change bundle ID of installed app ip_path = os.path.join(app_path, 'Contents/Info.plist') bundle_id = '{0}.{1}'.format(wf().bundleid, uuid.uuid4().hex) data = plistlib.readPlist(ip_path) log().debug('Changing bundle ID to {0!r}'.format(bundle_id)) data['CFBundleIdentifier'] = bundle_id plistlib.writePlist(data, ip_path)