SwiftBar icon indicating copy to clipboard operation
SwiftBar copied to clipboard

Expect spawn doesen´t work during hidden terminal

Open warmup72 opened this issue 2 years ago • 4 comments

I want to start Forklift (or any other Application) as root-user. So I´ve set up a little script with a expect/spawn-Command. This Command works on Terminal and also with Swiftbar-Execute setting "terminal=true". But is I set terminal=false it doesn´t work anymore:

admuser=[Adminuser]
pw=[Admin-Password]
app="/Applications/ForkLift.app/Contents/MacOS/ForkLift"
expect -c "spawn su - $admuser -c \"echo "$pw" | sudo -S nohup $app &>/dev/null &  \";expect \"Password:\";send \"${pw}\n\";interact"

macOS 12.5.1 Swiftbar 1.4.4

warmup72 avatar Sep 10 '22 15:09 warmup72

Do you have a ready to use plugin I can use for debugging?

melonamin avatar Sep 13 '22 18:09 melonamin

Sorry for the delay - The following script starts contact as example as root. If You set terminal=true it works. With terminal=false nothing happens:

#!/bin/bash
if [ "$1" == 'app' ]; then
	admuser="[ADMINUSER]"
    pw="[ADMINPASSWORD]"
    app="/System/Applications/Contacts.app/Contents/MacOS/Contacts"
    expect -c "spawn su - $admuser -c \"echo "$pw" | sudo -S nohup $app &>/dev/null &  \";expect \"Password:\";send \"${pw}\n\";interact"
    exit
fi

    echo "test"
	echo "Start App as Root |  bash='$0' param1='app' terminal=false refresh=false"
exit

warmup72 avatar Sep 14 '22 17:09 warmup72

Well, it works on this build for me:

https://user-images.githubusercontent.com/222100/190278883-e2e7c8ba-c601-4b8d-a270-305bfe6a3335.mp4

Slightly modified plugin source:

#!/bin/bash

if [ "$1" == 'app' ]; then
    admuser="user"
    pw="password"
    app="/System/Applications/Contacts.app/Contents/MacOS/Contacts"
    expect -c "spawn su - $admuser -c \"echo "$pw" | sudo -S nohup $app &>/dev/null &  \";expect \"Password:\";send \"${pw}\n\";interact"
    exit
fi


echo "test"
echo "---"
echo "Start App as Root |  bash='$0' param1='app' terminal=false refresh=false"
echo "Start App as Root Terminal |  bash='$0' param1='app' terminal=true refresh=false"

Any other detials you can provide? Maybe a dump of defaults

melonamin avatar Sep 14 '22 23:09 melonamin

Hm, I´ve tried it with the new build. On my MBP (12.6 and before with 12.5) same Problem. The Terminal-Link works an Contact starats The other link didn´t bring up the Contacts. Seems that something with the config is different

warmup72 avatar Sep 15 '22 04:09 warmup72

@warmup72 👋

It is still working for me on the latest beta build, mind trying it if the issue is still relevant to you?

melonamin avatar Dec 30 '23 14:12 melonamin

Sorry - I´ve tried this now an it also works for me - don´t know what before went wrong

warmup72 avatar Dec 30 '23 15:12 warmup72