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

Sharing and discussing custom actions for LaunchBar
bitSchleuder
Posts: 1
Joined: Mon Sep 18, 2017 10:02 pm

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

Postby bitSchleuder » Mon Sep 18, 2017 10:23 pm

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 Console.app:

Code: Select all

do shell script "sudo " & (quoted form of "/Applications/Utilities/Console.app/Contents/MacOS/Console") 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 Console.app 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/Console.app/Contents/MacOS/Console"
    set command to "sudo " & (quoted form of "/Applications/Utilities/Console.app/Contents/MacOS/Console")
    do shell script "sudo " & (quoted form of "/Applications/Utilities/Console.app/Contents/MacOS/Console") 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:

Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 2 guests