r/applescript • • Mar 04 '23

Help! Progressbar doesn't show while called from shell.

I'm fiddling with applescript that makes a progressbar.

set progress description to "A simple progress indicator"
set progress additional description to "Preparing…"
set progress total steps to -1

delay 0.1

set progress total steps to 30
repeat with i from 1 to 30
	try
		set progress additional description to "I am on step " & i
		set progress completed steps to i
		delay 0.1
	on error thisErr
		display alert thisErr
		exit repeat
	end try
end repeat
-- Taken and edited from https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/DisplayProgress.html

While run in the script editor, I can see the progress icon running. However, when I call the script with shell osascript ~/the_script.scpt, it only hangs for 3 seconds and exits without showing any progressbar. Additionally, I do need to run it from shell, because at the end I hope other types off applications (e.g. emacs) can call a progressbar too.

How do I fix this issue?

1 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/porkchop_d_clown Mar 04 '23

The syntax for the "tell" command is:

tell application "Finder"

-- do stuff --

end tell

But don't bother, I just tried it and it doesn't work. I googled around and while I've found other people with the same complaint you have. I don't see an answer, it may simply not be supported by osascript.

However, I tried this and it works, although it's not what you want. You might be able to adapt it to your needs:

delay 0.1

repeat with i from 1 to 30
    try

	display notification "I am on step" & i with title "Test App"
	
	delay 0.1
    on error thisErr
	display alert thisErr
	exit repeat
    end try
end repeat

I do not recommend displaying 30 notifications at .1 second intervals, though. ;-)

2

u/stuudente Mar 04 '23

Yeah.. showing notification a lot isn't really what I'm looking for. Thank you for your help though :)