MacOS – Add a startup script in macOS High Sierra 10.13.2

bashmacosscriptterminal

I have a weather station program that I would like to run automatically in Terminal when I log in. I manually have to run this every time I log in. This is the simple script I would like to automate:

cd desktop
cd cumulusmx
sudo mono cumulusmx.exe

(mono asks for system password which is entered in on next line)

password

I am sure this is simple, but I am just starting out in macOS after many, many years of being a Microsux user. Any simple solutions?

Best Answer

Testing this under macOS Sierra 10.12.6, I did not find it necessary to use the sudo command to run CumulusMX.exe using mono.

At a minimum, the following example AppleScript code can be used in Script Editor to create an AppleScript application that you can add to your Login Items.

tell application "Terminal"
    do script "cd $HOME/Desktop/CumulusMX; /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono CumulusMX.exe"
end tell

To use the example AppleScript code, copy and paste the code into a new document in Script Editor and then save it as an application, e.g.: Cumulus MX

Then add Cumulus MX to: System Preferences > Users & Groups > $USER > Login Items

I’d like to mention that if I was doing this on my system the CumulusMX folder would not be on my Desktop, as IMO that’s not an appropriate place to put it. Also, in testing the example AppleScript code, I did not find it necessary to use the sudo command to run mono, however if for some reason you need to do that, then additional steps would need to be taken but not recommended to automate.


Note: The example AppleScript code is just that and does not include any error handling as may be appropriate/needed/wanted, the onus is upon the user to add any appropriate error handling for any example code presented.