How can I run a command in a terminal at startup then have the terminal close while command continues

There could be a completely different way to do this but this works as long as I leave the terminal open. My goal is to be able to close the terminal and leave the command running.


I need to announce a bonjour service using the following command


dns-sd -R "Ion AirCopy" _uscan._tcp local 80 "note=AirScan for s400w" "duplex=F" "is=adf" "cs=color" "pdl=image/jpeg" "uuid=4509a320-00a0-008e-00b6-000507510ecc" "rs=eSCL" "representation=http://192.168.0.117/icon.png" "vers=2.2" "usb_MDL=AirCopy" "usb_MFG=Ion" "mdl=AirCopy" "mfg=Ion" "ty=Ion AirCopy" "adminurl=http://192.168.0.117/index.php" "txtvers=1"


but I want the window to close and leave it running.


Any suggestions?

Mac mini, macOS 10.15

Posted on Jan 29, 2022 4:10 PM

Reply

Similar questions

9 replies

Jan 31, 2022 2:25 AM in response to markosjal

Ok here is what I figured out


First no fancy line breaks only continuous text

Select /bin/bash from drop down menu


nohup dns-sd -R "Ion AirCopy" _uscan._tcp local 80 "note=AirScan s400w" "duplex=F" "is=adf" "cs=color" "pdl=image/jpeg" "uuid=4509a320-00a0-008e-00b6-000507510ecc" "rs=eSCL" "representation=http://192.168.0.117:80//Library/WebServer/Documents/icon.png" "vers=2.2" "usb_MDL=AirCopy" "usb_MFG=Ion" "mdl=AirCopy" "mfg=Ion" "ty=Ion AirCopy" "adminurl=http://192.168.0.117:80/index.php" "txtvers=1" >/dev/null 2>&1 &




This works pasting into automator. The process keeps running and no window is seen. It eliminates the constant spinning disc at the top status bar.


Why I even need automator is beyond me. Add insult to injury that it does not seem documented rather is "guessware" and subject to Apple's Changes on a whim. The need for automator makes one unnecessary, and difficult step when trying to mass produce a solution. Why an I simply not able to run a shell script at start up? I guess that's what you get from "fluffy" OS.


What a convoluted solution. I would hope for something more elegant on a Mac but unless you are the elite "Apple developer" you get nothing.

Jan 29, 2022 11:43 PM in response to markosjal

I pasted this into automater earlier and it works

#!/bin/bash
nohup dns-sd -R "Ion AirCopy" _uscan._tcp local 80 "note=AirScan for s400w" "duplex=F" "is=adf" "cs=color" "pdl=image/jpeg" "uuid=4509a320-00a0-008e-00b6-000507510ecc" "rs=eSCL" "representation=http://192.168.0.117/icon.png" "vers=2.2" "usb_MDL=AirCopy" "usb_MFG=Ion" "mdl=AirCopy" "mfg=Ion" "ty=Ion AirCopy" "adminurl=http://192.168.0.117/index.php" "txtvers=1" &
Exit



Then I tried it your way and now can not even post my previous version into automator . No matter what I do now I get The action run shell script encountered an error, "DNSService Call Failed 65540"


Something is very strange for such inconsistent behavior

Jan 30, 2022 8:41 AM in response to markosjal

I knew how to create an Automator "Run Shell Script" app. I do not know a thing about dns-sd, so why you got a DNSService error, I cannot tell you.


Then again, why use nohup and & as you have a dedicated app that is not taking up any desktop space, and will be happy to wait around forever for the command to finish.


Also while debugging it is better to minimize your complications, so until you have it working, stop using nohup and &


If you do not want to use Automator, you could try Platypus

https://sveinbjorn.org/platypus

Which will wrap any script you write into a double-clickable app. I've also used that before I switched mostly to Automator. But one thing I still use Platypus for is a menu bar app. The guts of the menu bar app is a 6,000 line script, but Platypus lets me control it from the menu bar which is very handy for what I'm doing with that script.

Jan 30, 2022 4:28 PM in response to BobHarris

Let me clarify,


I have developed a third party driver for a scanner\. That scanner was abandoned by Apple and Manufacturer(s) long ago with 64 bit code.


Because the new method for scanning on macOS is eSCL/AirScan it is all web based. So I have some PHP code that installs into the MacOS web server and an executable for OSX_64 (none for M1 Chip yet), that together do the work for communicating between like preview.app or imaging.app and the scanner (by way of embeded web server and PHP) . So for the purposes of installing I need to be able to CONSISTENLTLY produce the code that then user will plug into Automator . As I understand it though "nohup" itself may be all I need, but not sure how it works either. So I need to be able to CONSISTENTLY generate the WORKNG code (seems problematic) in PHP that works in Automator. I now have two files that look nearly identical to me one works fine in automator and the other does not. I am beginning to suspect an invisible character like an EOL. As I said it is all generated in PHP.


Automator for example says to insert the shell script . My shell script starts with #1/bin/bash but do I need that in automator or just select /bin/bash from the drop down menu. Is automator "Guessware" or is there a real manual for it somewhere?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How can I run a command in a terminal at startup then have the terminal close while command continues

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.