Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a progress bar to a dialog for a "do shell script" in AppleScript

I have an app I'm working on written in AppleScript that moves the St. Bernard redirect LaunchDaemon to the current user's directory so that the user can access any website at home, but lets them put it back before they go back to school. The reason for this is that at school, iPrism blocks whatever website the school doesn't want you going to, but the St. Bernard LaunchDaemon blocks the same websites when the students are at home, and I think that it's unnecessary to do that.

Anyway, I want to add a progress bar to a dialog that shows the input of the shell script that removes the app. Anyone know how to do that?

(I also wanted to not have any buttons on the display dialog "Removing..." buttons "", but instead just have the progress bar. Is this possible?)

Here is the code:

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

Thanks in advance for anyone who can help!

like image 512
SchoolDev Avatar asked Feb 12 '23 08:02

SchoolDev


1 Answers

Applescript in MacOS X 10.10 or later has built-in terminology for a progress bar. For applets, it runs a progress indicator in a dialog box. In script editor, it shows in the status bar. Adapt this terminology:

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
like image 151
jweaks Avatar answered Apr 27 '23 07:04

jweaks