swiftbar / SwiftBar

Powerful macOS menu bar customization tool
https://swiftbar.app
MIT License
2.93k stars 92 forks source link

Expect spawn doesen´t work during hidden terminal #332

Closed warmup72 closed 10 months ago

warmup72 commented 2 years ago

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

melonamin commented 2 years ago

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

warmup72 commented 2 years ago

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
melonamin commented 2 years ago

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

warmup72 commented 2 years ago

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

melonamin commented 10 months ago

@warmup72 👋

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

warmup72 commented 10 months ago

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