Page 1 of 1

JavaScript action running AppleScript - do shell script with administrator privileges - failed

Posted: Mon Sep 18, 2017 10:23 pm
by bitSchleuder
Hi @all,

don't know what's going wrong with my JavaScript action.

So what do I wanted to do with LaunchBar:
- selecting an app in LaunchBar
- Pressing <TAB> to change to an action
- executing my self-made action

My self-made action will do the following:
- Open a GUI app as admin

That's my code:

Code: Select all

function run(argument) {
    if (argument == undefined) {
        // Inform the user that there was no argument
        LaunchBar.alert('No argument was passed to the action');
    } else {
        var item = argument[0];
        var appName = item.substring((item.lastIndexOf('\/') + 1), (item.lastIndexOf('.')));
        var appPath = item + "/Contents/MacOS/" + appName;
        var scriptCall = 'do shell script "sudo " & (quoted form of "' + appPath + '") with administrator privileges';
        LaunchBar.debugLog(LaunchBar.executeAppleScript('\n', scriptCall));
        // Return a single item that describes the argument
        return [{ title: '1 argument passed' }, { title: item }];

The AppleScript shell script string will be like this, in case of

Code: Select all

do shell script "sudo " & (quoted form of "/Applications/Utilities/") with administrator privileges

So I've done the same with Alfred 3 workflows, in plain AppleScript, running fine.

Now with LunchBar I will get the following errors in the logging:

    21:56:24.069190 +0200 authd Failed to authorize right 'system.privilege.admin' by client '/usr/bin/osascript' [18050] for authorization created by '/usr/bin/osascript' [18050] (13,0) (-60007)
    21:56:24.079707 +0200 CommCenter #I CSIAppInfo.ApplicationActivationObserver: handleLSNotitifcation_sync: Application exited: <private>
    21:56:24.139727 +0200 LaunchBar As Admin (de.bitschleuder.LaunchBar.action.bitschleuder.AsAdmin):
    21:56:24.139916 +0200 LaunchBar As Admin (de.bitschleuder.LaunchBar.action.bitschleuder.AsAdmin): Message: set appName to quoted form of "/Applications/Utilities/"
    set command to "sudo " & (quoted form of "/Applications/Utilities/")
    do shell script "sudo " & (quoted form of "/Applications/Utilities/") with administrator privileges

If I run the AppleScript do shell in my shell with /usr/bin/osascript manually, I have to add -e(xecute) to the AppleScript string.

Is there something to turn on in LunchBar to get the osascript running with my administrator privileges?

I'm using LunchBar not as admin user but I'm part of the sudo user group.

My System is macOS 10.12.6, LaunchBar Version 6.9 (6144)

Does anyone have any ideas? :roll: