Script to run 'Topgrade in Terminal'

This should be so easy but I can’t get it to work…

I want to open Terminal and run the ‘Topgrade’ command, this is activated by an Apple Shortcut.

No ideas what I’m missing. :slight_smile:

Please show what you’ve done so far

So embarrassing I was just trying… And yeah I’ve no ideas what I’m doing! :slight_smile:

Is this in Automator, or an actual AppleScript?

Here’s my AppleScript

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

local aTab
tell application "Terminal"
	activate
	delay 1
	set aTab to tab 1 of window 1
	do script "Topgrade" in aTab
end tell

An Apple shortcut doesn’t run the script in the Terminal app.
It runs it invisibly in memory in the shell chosen

BTW what does topgrade do?
It gives me an error when I try to run it in the terminal, saying command not found

** EDIT ** fixed a variable typo

Right, I’ll try that tomorrow, watching family TV at the moment. Many thanks. [Edit I tried it] I get errors:

/Users/myuser/Library/Group Containers/group.com.apple.shortcuts/Temporary/com.apple.WorkflowKit.BackgroundShortcutRunner/94F7D0D1-5AEE-4019-9C01-6A9B23EF9C20:1: unknown file attribute: 1
/Users/myuser/Library/Group Containers/group.com.apple.shortcuts/Temporary/com.apple.WorkflowKit.BackgroundShortcutRunner/94F7D0D1-5AEE-4019-9C01-6A9B23EF9C20:2: command not found: use
/Users/myuser/Library/Group Containers/group.com.apple.shortcuts/Temporary/com.apple.WorkflowKit.BackgroundShortcutRunner/94F7D0D1-5AEE-4019-9C01-6A9B23EF9C20:5: command not found: tell
/Users/myuser/Library/Group Containers/group.com.apple.shortcuts/Temporary/com.apple.WorkflowKit.BackgroundShortcutRunner/94F7D0D1-5AEE-4019-9C01-6A9B23EF9C20:6: command not found: activate
/Users/myuser/Library/Group Containers/group.com.apple.shortcuts/Temporary/com.apple.WorkflowKit.BackgroundShortcutRunner/94F7D0D1-5AEE-4019-9C01-6A9B23EF9C20:7: command not found: delay
/Users/myuser/Library/Group Containers/group.com.apple.shortcuts/Temporary/com.apple.WorkflowKit.BackgroundShortcutRunner/94F7D0D1-5AEE-4019-9C01-6A9B23EF9C20:9: parse error near `do'

The shortcut was:

This is Topgrade:

It’s used to update various bits and pieces installed via HomeBrew.
The thought is if I can run it from a Shortcut I can them automate it via Shortery and get it to run automatically :slight_smile:

It’s not a shell script. It’s an AppleScript. You run it in Script Editor

Here is the Shortcut version

image

You’ll have to enable Scripts to be run in Shortcuts

Ah right, I did say I was new to all this. That gets further but I now get a different error. I’m pretty sure I go it all in there correctly…

When your terminal program launches, does a Window show up?

This is so weird. I’ve been watching TV and decided to run it again (no changes made), it looks like it ran perfectly:

I guess all I need now is to close the terminal window?

Ah ha the error occurs if a Terminal window is already open.

Here is a modified version which test for already open window…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Terminal"
	set f to not (running)
	activate
	if f then delay 1
	if (count windows) = 0 then
		do script "Topgrade"
	else
		do script "Topgrade" in tab 1 of window 1
	end if
end tell

That works perfectly my thanks!