<div dir="ltr">Hey Ian,<div><br></div><div>Thanks for the offer, unfortunately, however, Pallet doesn&#39;t run any shell commands (everything is passed done through spinning up a Tcl shell and passing input/output through IPC), so I&#39;m afraid your example wouldn&#39;t work.</div><div><br></div><div>Thanks again, though!</div><div>-Kyle</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 5:25 PM, Ian Wadham <span dir="ltr">&lt;<a href="mailto:iandw.au@gmail.com" target="_blank">iandw.au@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 06/08/2015, at 4:14 AM, Kyle Sammons wrote:<br>
<br>
&gt; Hey everyone,<br>
&gt;<br>
&gt; Currently I&#39;m at a fork in the road for the Revitalizing Pallet GSoC<br>
&gt; project, and was hoping to crowd source some ideas about how to deal<br>
&gt; with the Apple authorization framework used to get super user privileges<br>
&gt; to allow &#39;port&#39; to execute correctly under the hood. This task is the<br>
&gt; last major one on my GSoC queue. There are three possible roads to go<br>
&gt; down here; I don&#39;t know which one is the &quot;best&quot; or &quot;correct&quot; one, hence<br>
&gt; the crowd sourcing here.<br>
<br>
</span>Here is another possibility, which I used in Fossick…  Note that I went the<br>
command-line route and used &quot;tail -f&quot; to receive output asynchronously.<br>
You may not need that if you have gone the other route.  The guts of the<br>
authorisation is to use AppleScript.  Hope this helps.<br>
<br>
/**<br>
 * This method uses AppleScript to run a privileged Unix script asynchronously<br>
 * in the background, with output to a file (e.g. a script containing MacPorts&#39;<br>
 * &quot;port install &lt;software item&gt;&quot; command).  The NSTask object defined above<br>
 * uses &quot;tail -f&quot; to collect the output as it occurs.  The return string is nil<br>
 * if the script started OK or contains an error text if it failed.  AppleScript<br>
 * is run &quot;with administrator privileges&quot;, which means that it pops up the usual<br>
 * Apple request for an admin password when installing non-Apple software.<br>
 */<br>
- (NSString *) runPrivilegedScript: (NSString *) filePath<br>
                            output: (NSString *) outputFilePath;<br>
-------------------------------------------------------------------------------------------------------<br>
<br>
- (NSString *) runPrivilegedScript: (NSString *) filePath<br>
                      output: (NSString *) outputFilePath<br>
{<br>
    NSDictionary * error;<br>
    NSString * script = [NSString stringWithFormat: @&quot;do shell script &quot; \<br>
                         &quot;\&quot;&#39;%@&#39; &gt;&#39;%@&#39; 2&gt;&amp;1 &amp;\&quot; &quot; \<br>
                         &quot;with administrator privileges &quot; \<br>
                         &quot;without altering line endings&quot;,<br>
                         filePath, outputFilePath];<br>
    NSLog(@&quot;SCRIPT: %@&quot;, script);<br>
    NSAppleScript * appleScript = [[NSAppleScript new] initWithSource:script];<br>
    if ([appleScript executeAndReturnError:&amp;error]) {<br>
        NSLog(@&quot;AppleScript running! &#39;%@&#39; &gt;&#39;%@&#39; 2&gt;&amp;1 &amp;&quot;, filePath, outputFilePath);<br>
<br>
        // Start the output-watcher.<br>
        self.task = [[NSTask alloc] init];<br>
        [self.task setLaunchPath:@&quot;/usr/bin/tail&quot;];<br>
        [self.task setArguments:[NSArray arrayWithObjects:<br>
                            @&quot;-f&quot;, outputFilePath, nil]];<br>
        self.tailOfOutput = [NSPipe pipe];<br>
        self.errorOutput  = [NSPipe pipe];<br>
        [self.task setStandardOutput: tailOfOutput];<br>
        [self.task setStandardError:  errorOutput];<br>
        [self.task setStandardInput: [NSPipe pipe]]; // No standard input.<br>
        [self.task launch];<br>
        [[self.tailOfOutput fileHandleForReading] readInBackgroundAndNotify];<br>
        [[NSNotificationCenter defaultCenter]<br>
                  addObserver: self<br>
                     selector: @selector (receiveOutput:)<br>
                         name: NSFileHandleReadCompletionNotification<br>
                       object: nil];<br>
        return nil;<br>
    }<br>
    else {<br>
        NSLog(@&quot;Failed to run AppleScript!\n%@&quot;, error);<br>
        return [error description];<br>
    }<br>
    // TODO:  &quot;User cancelled.&quot; is a possible error reason (i.e. hit Cancel<br>
    //        instead of entering a password).  OS X seems to allow unlimited<br>
    //        failed attempts to enter the password.<br>
<span class="">}<br>
<br>
&gt; 0. Do nothing; leave the current code in place, but continue to ignore<br>
&gt; it; require the user to run it with superuser privileges;<br>
</span>&lt;snip&gt;<br>
<br>
Cheers, Ian W.<br>
<br>
</blockquote></div><br></div>