0

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?

  • If you need sudo, I don't see any way to do this short of storing your password in the script. Which is possible, but a bad idea idea for obvious reasons. – Wowfunhappy Jan 5 '18 at 17:50
  • You could set up a launchdaemon to run the script, as launchdaemons always run as root. But then you wouldn't be able to actually interact with the weather station program, as it's stuck in a root shell. – Wowfunhappy Jan 5 '18 at 17:53
1

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.

  • 1
    Instead of Applescript, it would probably be simpler/cleaner to put the bash script itself in a *.command file. You can add a script with this extension to Login Items just like an app. – Wowfunhappy Jan 5 '18 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .