【右键菜单扩展】以管理员身份打开文件(夹)
Tofloor
poster avatar
忘记、过去
deepin
2020-09-13 20:55
Author
本帖最后由 zty199 于 2020-9-15 01:53 编辑








按照 @lidanger 大佬的建议,去掉了只能打开文件的限制,现在也可以用来打开文件夹了。输入密码的对话框用的 zenity 生成,如果想换成 pkexec 的话直接修改 /usr/bin/admin-xdg-open 即可,里面有注释。

不过注意,虽然可以以管理员身份打开文件夹,但是这时候直接打开文件还是会假死。继续右键点击“以管理员身份打开文件(夹)”这样倒是不会死机......不过这样就多此一举了,主要还是方便文件移动删除等操作才加上文件夹打开支持的。

P.S>存在一个问题,装了 vscode 会替换文件夹默认打开方式。需要在 root账户 里修改文件夹默认打开方式为 文件管理器 才行。这就是 xdg-open 的问题了......更多的小问题可以看楼下 lidanger 大佬的回复,不是啥文件都能用 xdg-open 打开的......
admin-xdg-open_1.1.1.tar.gz


Reply Favorite View the author
All Replies
sgb76
deepin
2020-09-13 21:09
#1
亲测有效,解决了以管理员身份打开文件夹再编辑文件,造成文管卡死的问题
Reply View the author
SamLukeYes
deepin
2020-09-13 21:14
#2
针对文本文件还有另一种解决方案,把 kate 或 vscode 设为默认文本编辑器,保存的时候会自动要求提权
Reply View the author
haohu1193
deepin
2020-09-13 21:20
#3
本帖最后由 haohu1193 于 2020-9-14 12:00 编辑

不容易啊...为了这点需求是改了又改...幸苦啦啊各位...









Reply View the author
辉夜
deepin
2020-09-13 21:28
#4
这是不是相当于用sudo打开文件?
Reply View the author
Comments
zty199
2020-09-14 01:51
是,本来想直接sudo dedit的,后来还是用xdg-open比较好、。、
haohu1193
deepin
2020-09-13 21:30
#5
节省了打开终端输入命令的步骤...也行...
Reply View the author
走钢丝
deepin
2020-09-13 22:43
#6
本帖最后由 lidanger 于 2020-9-13 16:08 编辑

既然折腾,这样不如建个脚本 /pathtofile/admin-xdg-open.sh

  1. #!/bin/bash

  2. pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY xdg-open $*
Copy the Code

然后把扩展改成

  1. [Desktop Entry]
  2. Type=Application
  3. Exec=/pathtofile/admin-xdg-open.sh %u
  4. GenericName=XDG_OPEN as Administrator
  5. Name=XDG_OPEN as Administrator
  6. MimeType=*
  7. GenericName[en]=XDG_OPEN as Administrator
  8. GenericName[zh_CN]=以管理员身份打开
  9. Name[en]=XDG_OPEN as Administrator
  10. Name[zh_CN]=以管理员身份打开
  11. X-DFM-MenuTypes=SingleFile
  12. X-DFM-SupportSchemes=file
  13. X-Deepin-Vendor=user-custom
Copy the Code

或者直接用 xdg-open 打开所有

  1. [Desktop Entry]
  2. Type=Application
  3. Exec=/pathtofile/admin-xdg-open.sh %u
  4. GenericName=XDG_OPEN as Administrator
  5. Name=XDG_OPEN as Administrator
  6. MimeType=*
  7. GenericName[en]=XDG_OPEN as Administrator
  8. GenericName[zh_CN]=以管理员身份打开
  9. Name[en]=XDG_OPEN as Administrator
  10. Name[zh_CN]=以管理员身份打开
  11. X-Deepin-Vendor=user-custom
Copy the Code

不过鉴于 xdg 不一定有关联程序,而且常用管理员权限打开的就是各种文本配置文件,不如改成以管理员身份编辑

admin-txt-edit.sh

  1. #!/bin/bash

  2. pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY dedit $*
Copy the Code

admin-txt-edit.desktop

  1. [Desktop Entry]
  2. Type=Application
  3. Exec=/pathtofile/admin-txt-edit.sh %u
  4. GenericName=dedit as Administrator
  5. Name=dedit as Administrator
  6. MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-patch;text/x-adasrc;text/x-chdr;text/x-csrc;text/css;application/x-desktop;text/x-patch;text/x-fortran;text/html;text/x-java;text/x-tex;text/x-makefile;text/x-objcsrc;text/x-pascal;application/x-perl;application/x-perl;application/x-php;text/vnd.wap.wml;text/x-python;application/x-ruby;text/sgml;application/xml;model/vrml;image/svg+xml;application/json;
  7. GenericName[en]=dedit as Administrator
  8. GenericName[zh_CN]=以管理员身份编辑
  9. Name[en]=dedit as Administrator
  10. Name[zh_CN]=以管理员身份编辑
  11. X-DFM-MenuTypes=SingleFile
  12. X-DFM-SupportSchemes=file
  13. X-Deepin-Vendor=user-custom
Copy the Code


Reply View the author
xhw
deepin
2020-09-14 00:28
#7
曲线救国也可以的啊
Reply View the author
舞天逸尘
deepin
2020-09-14 00:50
#8
星火商店有这个插件 直接安装就行了
Reply View the author
忘记、过去
deepin
2020-09-14 01:54
#9
https://bbs.deepin.org/post/201974
既然折腾,这样不如建个脚本 /pathtofile/admin-xdg-open.sh

别说了,下午发帖前打了一大段话的,结果一直提示不良信息发不了,还赶着CCF考试,就删的只剩图和压缩包了......
晚点我再看看pkexec,才知道要指定屏幕和授权
Reply View the author
海天鹰
deepin
2020-09-14 02:55
#10
这个必须有!
Reply View the author
忘记、过去
deepin
2020-09-14 05:22
#11
更新一下,用 zenity 替代了 deepin-terminal 输入密码,有需要的可以自己修改 /usr/bin/admin-xdg-open 使用 pkexec 输入密码。

如果因为安装了 vscode 导致打开文件夹时不能调用文管,可以如下操作:

先执行 sudo init 3 切换到 tty 文本界面登录,用户名 root,密码和用户密码相同,登录后执行 startx 开启图形界面。

打开文管,右键任意文件夹,打开方式中设置 文件管理器 为默认打开方式即可,之后可以重启,或者注销后在 tty 登录自己的账户,再执行 sudo init 5 回到图形界面。
Reply View the author
158******41
deepin
2020-09-14 05:38
#12
向善于思考、善于动手、善于分享的英雄致敬
Reply View the author
小明Hackintosh
deepin
2020-09-14 19:05
#13
我在想,这个右键打开会不会以后学习水果做成收费的右键功能呀。
Reply View the author
忘记、过去
deepin
2020-09-14 20:39
#14
https://bbs.deepin.org/post/201974
我在想,这个右键打开会不会以后学习水果做成收费的右键功能呀。

macOS上也是免费的啊,叫超级右键better365他们家的东西挺好使的
Reply View the author
cellon
deepin
2020-09-14 21:20
#15
这个的确有用,不会在以管理员身份打开文本编辑器时卡死,星火商店那个会卡死。
Reply View the author
Comments
zty199
2020-09-14 21:37
这个也在星火商店有 XD,只是打开的时候没有经过文件管理器所以不会卡死
cellon
deepin
2020-09-15 22:02
#16
https://bbs.deepin.org/post/201974
这个的确有用,不会在以管理员身份打开文本编辑器时卡死,星火商店那个会卡死。
...

好吧,听你的,今天上来看到又更新到1.1.1了,不知道主要更新了什么?
Reply View the author
Comments
zty199
2020-09-19 07:07
基本没改,之前版本少打包 zenity 的依赖,要加进去......