Jump to content
nikivi

How to get around permission denied issue in Alfred?

Recommended Posts

Posted (edited)

I want to make a simple workflow that searches /Applications dir for apps and then on activating will move the item to trash.

 

I can't do this from Alfred due to Permission denied error. I tried prepending the mv command with sudo but that doesnt work either. Is there any other way to get around this issue? I want to quickly search through apps I own and move them to trash where Hazel than picks it up and offers to remove supplement files for the app.

 

Thank you for any help. 

Edited by nikivi

Share this post


Link to post
43 minutes ago, nikivi said:

I tried prepending the mv command with sudo but that doesnt work either

 

Obviously. sudo requires you to enter your password.

 

Either ask Finder to trash the file for you, or better yet, create a File Action that opens it in AppCleaner, which will also trash the app's other files and stop you trashing a system application like Safari.

 

Share this post


Link to post
13 minutes ago, deanishe said:

sudo requires you to enter your password

 

Yeah I stupidly thought it would prompt me.

 

AppCleaner is good choice. I wanted to move away from this workflow but will probably end up using it again. I just wanted to get rid of CMM as I dont use it much and want to keep a clean OS.

Share this post


Link to post
Just now, nikivi said:

Yeah I stupidly thought it would prompt me

 

Only in an interactive shell. You can use AppleScript:

do shell script "command here" with administrator privileges

 

Share this post


Link to post
11 hours ago, nikivi said:

I just wanted to get rid of CMM as I dont use it much and want to keep a clean OS.

 

Not wanting extra apps for these kinds of tasks is exactly why I made DeleteConfig.

 

11 hours ago, deanishe said:

Either ask Finder to trash the file for you

 

Curiously enough, I’ve worked on that a few days ago. In JXA:

#!/usr/bin/osascript -l JavaScript

function run(argv) {
  Application('Finder').delete(argv.map(p => Path(p)))
}

 

11 hours ago, deanishe said:

 

Only in an interactive shell. You can use AppleScript:


do shell script "command here" with administrator privileges

 

 

This is the right approach for such a small command. For completeness, sudo can indeed show you a graphical prompt but you have to specify it yourself. Search man sudo for SUDO_ASKPASS. Example on macOS:

readonly ask_pass_script="$(
  script="$(mktemp).scpt"

  echo '#!/usr/bin/osascript
    return text returned of (display dialog "Insert your password" with title "Administrator password needed" default answer "" buttons {"Cancel", "OK"} default button "OK" with hidden answer)
  ' > "${script}"
  chmod +x "${script}"

  echo "${script}"
)"

export readonly SUDO_ASKPASS="${ask_pass_script}"

Then you sudo --askpass {command}.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×