def get_bundle_identifier_for_path(path): """ Get bundle identifier for the given path. """ bundle_url = 'file://' + os.path.abspath(path) return NSBundle.bundleWithURL_( NSURL.URLWithString_(bundle_url)).bundleIdentifier()
def openUrl(self, url, background=False): ws = NSWorkspace.sharedWorkspace() option = NSWorkspaceLaunchDefault if background: option = NSWorkspaceLaunchWithoutActivation ws.openURL_options_configuration_error_(NSURL.URLWithString_(url), option, dict(), None)
def goto(self, url, show=True): if self._webkit is None: raise RuntimeError("needs to be a web window") url = NSURL.URLWithString_(url).retain() request = NSURLRequest.requestWithURL_(url) self._webkit.mainFrame().loadRequest_(request) self.show()
def sethtml(self, html, url, show=True): if self._webkit is None: raise RuntimeError("needs to be the web window") url = NSURL.URLWithString_(url).retain() if isinstance(html, str): html = html.decode("utf-8") self._webkit.mainFrame().loadHTMLString_baseURL_(html, url) self.show()
def upload(self, app): if app == 'local': pass else: url = CREATE_URL[app] + urlencode(self.CONTENTS, quote_via=quote) ws = NSWorkspace.sharedWorkspace() ws.openURL_options_configuration_error_( NSURL.URLWithString_(url), NSWorkspaceLaunchWithoutActivation, None, None)
def launchAppByBundlePath(bundlePath, arguments=[]): ''' launchAppByBundlePath - Launch app with a given bundle path Return True if succeed ''' bundleUrl = NSURL.URLWithString_(bundlePath) workspace = AppKit.NSWorkspace.sharedWorkspace() arguments_strings = map(lambda a: NSString.stringWithString_(str(a)), arguments) arguments = NSDictionary.dictionaryWithDictionary_({ AppKit.NSWorkspaceLaunchConfigurationArguments: NSArray.arrayWithArray_(arguments_strings) }) return workspace.launchApplicationAtURL_options_configuration_error_( bundleUrl, AppKit.NSWorkspaceLaunchAllowingClassicStartup, arguments, None)
def ensure_permissions() -> None: from ApplicationServices import AXIsProcessTrusted from AppKit import NSAlert, NSAlertFirstButtonReturn, NSWorkspace, NSURL accessibility_permissions = AXIsProcessTrusted() if not accessibility_permissions: title = "Missing accessibility permissions" info = "To let ActivityWatch capture window titles grant it accessibility permissions. \n If you've already given ActivityWatch accessibility permissions and are still seeing this dialog, try removing and re-adding them." alert = NSAlert.new() alert.setMessageText_(title) alert.setInformativeText_(info) ok_button = alert.addButtonWithTitle_("Open accessibility settings") alert.addButtonWithTitle_("Close") choice = alert.runModal() print(choice) if choice == NSAlertFirstButtonReturn: NSWorkspace.sharedWorkspace().openURL_( NSURL.URLWithString_( "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility" ))
def open_URL(url): """Open the url with launchservices.""" URL = NSURL.URLWithString_(url) LSOpenCFURLRef(URL, None)
def helpButtonPressed_(self, sender): # open help url NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_("Attribution"))
def donateButtonPressed_(self, sender): NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_("https://paypal.com"))
def helpButtonPressed_(self, sender): # open help url NSWorkspace.sharedWorkspace().openURL_( NSURL.URLWithString_( "http://code.google.com/p/quotefixformac/wiki/CustomAttribution" ))
def donateButtonPressed_(self, sender): NSWorkspace.sharedWorkspace().openURL_( NSURL.URLWithString_( "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4UF2KB2BTW6AC" ))
def howToUseMyOwnDomain_(self, sender): NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_("http://myownsipdomain.sip2sip.info"))
def set(self, url): if url is not None: url = NSURL.URLWithString_(url) self._nsObject.setURL_(url)