使用管理员权限自定义图标执行 Shell 脚本
Do Shell Script with Admin Privileges Custom Icon
我正在使用 AppleScript 作为管理员 运行 一个 shell 脚本。
do shell script custom_command with prompt custom_prompt with administrator privileges
这给了我这个很好的提示,但我希望能够将图标更改为终端图标以外的其他图标。任何帮助将不胜感激。
身份验证对话框中的徽章来自正在使用该命令的应用程序。
要获得图标的自定义徽章,您可以使用辅助 AppleScript 应用程序来 运行 您的脚本,但是如果 osascript
就是您所做的全部,您可以通过使用应用程序(否则你所做的就是使用 osascript
到 运行 AppleScript 运行 是 osascript
)。要为 osascript
创建应用程序,请在 脚本编辑器 中编辑您的脚本,例如:
do shell script "echo 'this is a test' >> ~/Desktop/Testing.txt" with administrator privileges
然后将其另存为应用程序(不要选中该选项)。将要使用的图标文件的副本重命名为 applet.icns,打开应用程序包,然后替换 /Contents/Resources 中现有的图标文件/。然后,您可以使用 open /path/to/your/app
从 终端 运行 应用程序
主图标仍是挂锁,但徽章现在是您的应用程序图标。
将参数传递给 application 与 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”
我正在使用 AppleScript 作为管理员 运行 一个 shell 脚本。
do shell script custom_command with prompt custom_prompt with administrator privileges
这给了我这个很好的提示,但我希望能够将图标更改为终端图标以外的其他图标。任何帮助将不胜感激。
身份验证对话框中的徽章来自正在使用该命令的应用程序。
要获得图标的自定义徽章,您可以使用辅助 AppleScript 应用程序来 运行 您的脚本,但是如果 osascript
就是您所做的全部,您可以通过使用应用程序(否则你所做的就是使用 osascript
到 运行 AppleScript 运行 是 osascript
)。要为 osascript
创建应用程序,请在 脚本编辑器 中编辑您的脚本,例如:
do shell script "echo 'this is a test' >> ~/Desktop/Testing.txt" with administrator privileges
然后将其另存为应用程序(不要选中该选项)。将要使用的图标文件的副本重命名为 applet.icns,打开应用程序包,然后替换 /Contents/Resources 中现有的图标文件/。然后,您可以使用 open /path/to/your/app
主图标仍是挂锁,但徽章现在是您的应用程序图标。
将参数传递给 application 与 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”