gpt4 book ai didi

terminal - 在 AppleScript 中为 "do shell script"的对话框添加进度条

转载 作者:行者123 更新时间:2023-12-04 23:20:46 25 4
gpt4 key购买 nike

我有一个用 AppleScript 编写的应用程序,它将 St. Bernard 重定向 LaunchDaemon 移动到当前用户的目录,以便用户可以访问家中的任何网站,但让他们在回学校之前将其放回原处。原因是在学校,iPrism 会屏蔽学校不想让你访问的任何网站,但是当学生在家时,St. Bernard LaunchDaemon 会屏蔽相同的网站,我认为没有必要这样做。

无论如何,我想向对话框添加一个进度条,该对话框显示删除应用程序的 shell 脚本的输入。有谁知道怎么做?

(我也不想在 display dialog "Removing..." buttons "" 上有任何按钮,而是只有进度条。这可能吗?)

这是代码:

display alert "You may have to restart your computer after using this tool!" buttons {"Ok"} default button 1

set question to display dialog "RMR (Remove My Redirect)

Are you unable to go to a website at home because of that annoying St. Bernard Redirect?

If the answer is Yes, then RMR is your solution! Simply Choose Remove to remove it, and Replace to put it back." buttons {"Remove", "Replace", "Erase Evidence"} default button 3
set answer to button returned of question

if answer is equal to "Remove" then do shell script "mv /Library/LaunchDaemons/com.stbernard.rfcd.plist ~/"

if answer is equal to "Replace" then do shell script "mv ~/com.stbernard.rfcd.plist /Library/LaunchDaemons/"

if answer is equal to "Erase Evidence" then set question to display dialog "Are you sure? RMR will be deleted forever." buttons {"Yes", "No"} default button 2
set answer to button returned of question

if answer is equal to "No" then do shell script "echo"

-- Progress bar goes on the below dialog

if answer is equal to "Yes" then ¬
tell application "Terminal"
display dialog "Removing..." buttons ""
do shell script "srm -rf ~/Downloads/RMR.app; history -c; killall Terminal"
delay 20
quit
end tell

提前感谢任何可以提供帮助的人!

最佳答案

Applescript 在 MacOS X 10.10或更高版本具有进度条的内置术语。对于小程序,它在对话框中运行进度指示器。在脚本编辑器中,它显示在状态栏中。调整这个术语:

set n to 10

set progress total steps to n
set progress description to "Script Progress"
set progress additional description to "This should be helpful"

repeat with i from 1 to n
delay 1
set progress completed steps to i
end repeat

关于terminal - 在 AppleScript 中为 "do shell script"的对话框添加进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27517042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com