使用管理员权限自定义图标执行Shell脚本

问题描述 投票:0回答:1

我正在使用AppleScript以管理员身份运行shell脚本。

do shell script custom_command with prompt custom_prompt with administrator privileges

这给了我这个提示很好,但我希望能够将图标更改为终端图标以外的其他内容。任何帮助,将不胜感激。

prompt

macos applescript
1个回答
1
投票

身份验证对话框上的徽章来自使用该命令的应用程序。

要获得图标的自定义徽章,您可以使用帮助AppleScript应用程序来运行您的脚本,但如果您正在使用osascript,您可以使用该应用程序执行所有操作(否则您所做的只是使用osascript来运行运行osascript的AppleScript)。要为osascript创建应用程序,请在脚本编辑器中编辑脚本,例如:

do shell script "echo 'this is a test' >> ~/Desktop/Testing.txt" with administrator privileges

然后将其保存为应用程序(保持选项未选中)。将要使用的图标文件的副本重命名为applet.icns,打开应用程序包,并替换/ Contents / Resources /中的现有图标文件。然后,您可以使用open /path/to/your/app从终端运行应用程序

主图标仍然是挂锁,但徽章现在将成为您的应用程序图标。

将参数传递给应用程序与osascript略有不同,但是一点点AppleScriptObjC会解决这个问题:

use framework "Foundation"
use scripting additions

# the first argument item is the applet/droplet executable path, so we'll just skip that
set args to rest of (arguments of current application's NSProcessInfo's processInfo() as list)

if args is not {} then
  do shell script "echo " & first item of args & " >> ~/Desktop/Testing.txt" with administrator privileges
end if

您可以使用open /path/to/your/app --args “this is a test”运行它

© www.soinside.com 2019 - 2024. All rights reserved.