Shortcuts app doesn't run a script as expected

Hello
Does anyone know why this snippet of code doesn’t work when invoked from Shortcuts?
When it’s launched from terminal or Tracker works flawlessly :thinking:
Tnx in advance

#! /bin/sh

while read app_name
do
	while read win_count
	do
		for ((count=0;count<${win_count};count++))
		do
			if [ "`timeout 1 hey -o "${app_name}" get Active of Window ${count}`" == "true" ]
			then
				alert "${app_name} ${count}"
				exit
			fi
		done
	done <<< `hey -o ${app_name} count of Window`
done <<< `roster | grep -v 'server' | awk '/\(/{print $2}' FS='[()]' | sort -u`

tbh not sure if I can answer this… from what I can tell, it looks like it should work (and you’d mentioned it works from Terminal, which I guess confirms my theory)… but ngl I haven’t tried a script in Shortcuts yet. But anyways, my first guess is chmod +x the script (like chmod +x ./windowing-script.sh) in Terminal and Identify the script in Tracker. If Haiku doesn’t get the MIME type, maybe try assigning it manually. If nothing works, I guess the last thing I’d say is maybe Shortcuts needs a Haiku executable to work… so last thing I’d try is maybe wrap the script inside a basic C program by calling the script in system();, compile it with gcc, and see if it works that way? Not sure what else I could give to help but I legit hope this helps :slight_smile:

Did you try
#! /bin/sh -l
?

1 Like

Possibly related to #12534?

2 Likes

Tnx for your reply, i already use shortcut to launch a script that prompt through alert a “power management menu” and this works, but it’s simpler than the previous one, this runs multiple instances so probably it cannot be done using input_server

Dunno, i will do some tests and let you know what happens ,tnx for your reply

1 Like

You are right, it needed some tweaks in my etc/profile but it worked, thanks :pray:

By the way you should not use

#! /bin/sh

but

#! /bin/bash

since you are using Bash syntax not POSIX syntax.

Both don’t work, the only way to get it working via shortcuts is running the script through -l argument