[SOLVED] Open as Admin menu choice using Right Click in Files

Please post suggestions for improvement of Cinnamon here
https://github.com/linuxmint/Cinnamon
Post Reply
wyattbiker
Level 1
Level 1
Posts: 32
Joined: Thu Jan 03, 2019 5:02 pm

[SOLVED] Open as Admin menu choice using Right Click in Files

Post by wyattbiker » Wed Jan 09, 2019 12:08 pm

I have Linux Mint 19.1 Cinnamon. Would like the ability to open applications as Admin by right clicking on the files or apps in either Nemo or Menu.
Anything available that can add that as a choice?

Thanks
Last edited by wyattbiker on Thu Jan 10, 2019 4:06 pm, edited 1 time in total.

redlined
Level 5
Level 5
Posts: 969
Joined: Wed Jun 06, 2018 8:12 pm
Location: Mile High, Green State! (Denver, CO;)

Re: Open as Admin menu choice using Right Click in Files

Post by redlined » Thu Jan 10, 2019 11:54 am

wyattbiker wrote:
Wed Jan 09, 2019 12:08 pm
I have Linux Mint 19.1 Cinnamon. Would like the ability to open applications as Admin by right clicking on the files or apps in either Nemo or Menu.
Anything available that can add that as a choice?

Thanks
I don't think there is a direct way to enable such Open as Admin in right click menu, it might could be done with a script file and using right click then Open with :?: as well you could probably create some launchers with elevated privilege,

before considering such perhaps you're probably better served using commands sudo, pkexec or admin:/// to open your files via command line in terminal with elevated privilege.

or right click in empty space in a directory and select Open as root to have file manager (nemo, in Cinnamon) reopen itself under Root privilege. Just be mindful to do only what is needed while in working from file manager as root and close when done to keep from navigating around and inadvertently changing permissions away from other user accounts where applicable, eg. while in file man as root any file you open/edit will also be run as root and saved as root owned when closed.
LM19.1 Cinnamon 4.0.9, kernel 4.18.0-15 x86_64
HP15 Laptop: 2Ghz Celeron quad core, 1TB 860 Evo SSD, 8GB Timetec RAM

My go to sites, besides this forum:
(start here! - EasyLinuxTips project then go Learn Linux-fu!

User avatar
trytip
Level 10
Level 10
Posts: 3395
Joined: Tue Jul 05, 2016 1:20 pm

Re: Open as Admin menu choice using Right Click in Files

Post by trytip » Thu Jan 10, 2019 12:41 pm

opening apps as root is dangerous if you have no experience which should be open as root so i will only post how to open in nemo and gedit as root you can replace any instance you see of gedit with xed
what i have done is this: i use nemo and gedit i have uninstalled xed since it doesn't support external tools but that's irrelevant for this you can modify the script to replace the scripts with xed if needed
go to .local/share/nemo/scripts/ if you don't have a folder named scripts inside .local/share/nemo/ create one
i'll start with two scripts. inside the folder scripts create two blank text files
1: 01-Open in NEMO-GEDIT
then paste, save and make executable by rightclicking/properties/permissions>check the Execute

Code: Select all

#!/bin/bash
#
# this code will determine exactly the path and the type of object,
# then it will decide use gedit or nemo to open it
#
#
# Nov 19, 2010
#Copyright by Nguyen Duc Long <Email: longnd.s8@gmail.com>
####################################################################################

# Determine the path
if [ -e -n $1 ]; then
	obj="$NEMO_SCRIPT_SELECTED_FILE_PATHS"
else
	base="`echo $NEMO_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
	obj="$base/${1##*/}"
fi
# Determine the type and open with file manager or file editor
if [ -f "$obj" ]; then
    gedit "$obj"
elif [ -d "$obj" ]; then
    nemo "$obj"
fi

exit 0
2: 02-Open in NEMO-GEDIT as ROOT

Code: Select all

#!/bin/bash
#
# this code will determine exactly the path and the type of object,
# then it will decide use gedit or nemo to open it by ROOT permission
#
#
# Nov 19, 2010
#Copyright by Nguyen Duc Long <Email: longnd.s8@gmail.com>
####################################################################################

# Determine the path
if [ -e -n $1 ]; then
	obj="$NEMO_SCRIPT_SELECTED_FILE_PATHS"
else
	base="`echo $NEMO_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
	obj="$base/${1##*/}"
fi
# Determine the type and run as ROOT
if [ -f "$obj" ]; then
	pkexec gedit "$obj"
elif [ -d "$obj" ]; then
	pkexec nemo "$obj"
fi

exit 0
when you want to open anything in filemanager or text editor as user or ROOT rightclick the folder/file>scripts

Image

here's another one to link anything to the desktop:
3: 03-Link To Desktop

Code: Select all

#!/bin/bash

DESKTOP=~/Desktop
 
if [ $# -lt 1 ] ; then
  zenity --error --text "At least one file or directory must be selected."
elif [ $# -gt 1 ] ; then
  zenity --question --text "Multiple items selected. Proceed?"
fi
 
if [ "$?" = 1 ] ; then
    exit 1
fi
 
for item in "$@"; do
    ln -s "$PWD/$item" "$DESKTOP/$(basename $item)"
done
 
exit 0
Last edited by trytip on Thu Jan 10, 2019 6:20 pm, edited 1 time in total.
Image

wyattbiker
Level 1
Level 1
Posts: 32
Joined: Thu Jan 03, 2019 5:02 pm

Re: Open as Admin menu choice using Right Click in Files

Post by wyattbiker » Thu Jan 10, 2019 4:06 pm

Thanks guys!

redlined
Level 5
Level 5
Posts: 969
Joined: Wed Jun 06, 2018 8:12 pm
Location: Mile High, Green State! (Denver, CO;)

Re: Open as Admin menu choice using Right Click in Files

Post by redlined » Thu Jan 10, 2019 6:04 pm

trytip wrote:
Thu Jan 10, 2019 12:41 pm
go to .local/share/nemo/scripts/ if you don't have a folder named scripts inside .local/share/nemo/ create one
sweet setup there trytip! might I bother you to share those other menu scripts as well? (they sure look handy and I've determined being a collector may serve me better as I cannot get past "flow control" (if, test, exit), :oops: my head starts exploding :mrgreen:
LM19.1 Cinnamon 4.0.9, kernel 4.18.0-15 x86_64
HP15 Laptop: 2Ghz Celeron quad core, 1TB 860 Evo SSD, 8GB Timetec RAM

My go to sites, besides this forum:
(start here! - EasyLinuxTips project then go Learn Linux-fu!

User avatar
trytip
Level 10
Level 10
Posts: 3395
Joined: Tue Jul 05, 2016 1:20 pm

Re: [SOLVED] Open as Admin menu choice using Right Click in Files

Post by trytip » Thu Jan 10, 2019 7:28 pm

i shall post one more for SHREDDING files. beware i edited the original script which was made to shred 50 times which is fine for very small files, but huge files like 1GB+ will kill your spinning drive so i lowered it to 5 times. usually 1 time shredding is good enough. if you want to go berserk you can edit "5" to more times, but i wouldn't suggest it. this is mainly good for small documents and pictures around 300-MB. the rest of my collection i have to revise as i haven't used these since the old ubuntu era and many are now obsolete.

i name them alpha numeric to me liking so they appear in context menu in order of my relevance.

04-File SHREDDER

Code: Select all

#!/bin/bash
#########################################################
#							#
# This are NScripts v3.6				#
#							#
# Licensed under the GNU GENERAL PUBLIC LICENSE 3	#
#							#
# Copyright 2007 - 2009 Christopher Bratusek		#
#							#
#########################################################

echo $NEMO_SCRIPT_SELECTED_URIS > ~/.gnome2/temp_shred_list

zenity --question --title "SHREDDER" --text "Shredding means *absolutely* destroy files!\n\nThe file is beeing overwritten 5 times and unrecoverable!\n \nCONTINUE?\n $(cat ~/.gnome2/temp_shred_list | sed -e 's/\%20/\ /g' -e 's/.*\///g')"

if (( $? == 0 )); then
	for file in $(cat ~/.gnome2/temp_shred_list); do

		shortfile=$(echo $file | sed -e 's/\%20/\ /g' -e 's/.*\///g')
		file_name=$(echo $file | sed -e 's/file:\/\///g' -e 's/\%20/\ /g')

		shred -u -z -n 5 --random-source=/dev/urandom "$file_name"
		if (( $? == 0 )); then
			zenity --info --text="$shortfile has been shred" --title "Success"
		else	zenity --info --text="$shortfile couldn't be shred" --title "Failure"
		fi
	done
fi

rm -f ~/.gnome2/temp_shred_list
unset XRETURN
if you want to create your own i have an unedited master for template. some may work some may not. i learned by trial and error download them >>> scripts_MASTER.tar.gz
Image

redlined
Level 5
Level 5
Posts: 969
Joined: Wed Jun 06, 2018 8:12 pm
Location: Mile High, Green State! (Denver, CO;)

Re: [SOLVED] Open as Admin menu choice using Right Click in Files

Post by redlined » Thu Jan 10, 2019 8:47 pm

trytip wrote:
Thu Jan 10, 2019 7:28 pm
if you want to create your own i have an unedited master for template. some may work some may not. i learned by trial and error...
Brilliant! Thank you for the extra script and explain, for sure!

and.... The treasure chest!! (thank you for sharing this! downloaded and tucked away for safe keeping :mrgreen:

ps... self is all I ever blame for those "reckless/'I wreck more' reinstall requirements", its always my choice :shock:
LM19.1 Cinnamon 4.0.9, kernel 4.18.0-15 x86_64
HP15 Laptop: 2Ghz Celeron quad core, 1TB 860 Evo SSD, 8GB Timetec RAM

My go to sites, besides this forum:
(start here! - EasyLinuxTips project then go Learn Linux-fu!

tony37
Level 1
Level 1
Posts: 8
Joined: Fri Jun 07, 2019 5:56 am

Re: [SOLVED] Open as Admin menu choice using Right Click in Files

Post by tony37 » Fri Jun 14, 2019 7:12 am

the second script "02-Open in NEMO-GEDIT as ROOT" only worked when I downloaded a PolicyKit file for gedit, following instructions from http://www.webupd8.org/2015/03/how-to-r ... -root.html, before that pkexec gedit wasn't working

gittiest personITW
Level 4
Level 4
Posts: 311
Joined: Tue May 28, 2019 4:27 pm

Re: [SOLVED] Open as Admin menu choice using Right Click in Files

Post by gittiest personITW » Mon Jun 17, 2019 8:59 am

Thank you for the scripts and the brilliantly easy instructions.
I look forward to destroying my system by accident now! Wheraarahahahahahahahahahahhahahahaha

Post Reply

Return to “Cinnamon”