I’m working on modifying our current script for Mac’s since the new mac’s came out. I’m using applescript and have a 17 different “do shell scripts” that do certain things like install software, bind to domain, etc. At then I have a delay restart command. The script runs, but I was curious if there was to add a progress bar or maybe configure it to show what step it’s on. Thanks in advance
If you want a log file on your progress this is one way to do it.
-- This creates a textfile with TextEdit and every my writeToLog adds what you want at the end of the text file.
my initLog()
-- your script goes here
-- Doing some stuff
-- Logging stuff done
my writeToLog("----------------------------------------------------------")
my writeToLog("Part one done")
-- Doing some more stuff
-- Logging stuff done
my writeToLog("Part two done")
my writeToLog("----------------------------------------------------------")
-- If you want to include variables in the log.
my writeToLog("Part Three done on " & yourVariableName & " sucessfully")
----------------------------------------------------------------------------------
-- Create log file subroutine
----------------------------------------------------------------------------------
on initLog()
set MyLogIntro to "Set your text here."
set logIntro to return & "My script started " & (current date) & return & return & ¬
"----------------------------------------------------------" & return
tell application "TextEdit"
activate
try
set noDocs to false
repeat until noDocs = true
if exists document 1 then
set noDocs to false
close document 1 saving no
else
set noDocs to true
end if
end repeat
end try
try
make new document at the beginning of documents with properties {text:logIntro}
set the bounds of the first window to {10, 0, 500, 500}
on error
display dialog "Could not create text window"
end try
end tell
end initLog
----------------------------------------------------------------------------------
-- Write to log subroutine
----------------------------------------------------------------------------------
on writeToLog(LineText)
tell application "TextEdit"
activate
try
tell text of document 1
set lastPara to (get the last paragraph as text)
set the last paragraph to (lastPara & LineText & return as string)
end tell
on error errtext number errnum
beep
activate me
display dialog "An error has occured: " & return & errtext & return & "Can't write to the log. [NotNumberedLogLine]" & return & ¬
"Cancelling..." buttons {"Cancel"} default button 1 with icon caution
end try
end tell
end writeToLog
You can use AppleScript’s progress properties. Here’s a sample of how:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set progress total steps to 10
set progress completed steps to 0
set progress description to "Starting"
set progress additional description to "Ready to go"
delay 1
set progress description to "Working"
repeat with i from 1 to 9
set progress completed steps to i
set progress additional description to "Step " & i
delay 1
end repeat
set progress completed steps to 10
As an alternative to those above, you can use a simple notification system such as:
myNotification("This is what I am doing", "Analysis of new files ")
on myNotification(myMainText, myTitle)
display notification (myMainText) with title myTitle sound name "Frog"
end myNotification