0

I've been reading this topic: Running script upon login mac and trying to follow its guidelines for using launchctl to create a bash shell script that runs automatically at login. I just CAN'T GET IT TO WORK! The shell script I want to launch is as follows:

#!/bin/bash
#
# Shell script to start the RobotFramework Auto-Started Servers.
#
# Copyright (c) 2014 Texas Instruments, Inc.
#
#-------------------------------------------------------------------------------
#
#
# Start the dispatcher as an independent background task with its own virtual screen
#
cd /Users/epsqainfprod/RobotFramework/Extensions/Dispatcher
screen -S Dispatcher -d -m ./StartDispatcher.sh
#
# Start the RunProcServer
#
cd /Users/epsqainfprod/RobotFramework/Extensions/RunProcess
screen -S RunProcServer -d -m ./RunProcServer.sh
#
#  -------------------------------- End of file --------------------------------

If I invoke this from the command line it works fine, creating two independently running, screen processes. I created a .plist file for this, following the instructions from the referenced post:

cat ~/Library/LaunchAgents/com.user.loginscript.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>com.user.loginscript</string>
   <key>Program</key>
   <string>/Users/epsqainfprod/TEMP/AutoStartScripts.sh</string>
   <key>RunAtLoad</key>
   <true/>
</dict>

where the above shell script is in the file /Users/epsqainfprod/TEMP/AutoStartScripts.sh. I've checked system.log and all it shows is:

Dec  2 08:05:49 epsqainf5lab15.itg.ti.com login[2109]: USER_PROCESS: 2109 ttys000
Dec  2 08:05:49 epsqainf5lab15.itg.ti.com login[2109]: DEAD_PROCESS: 2109 ttys000
Dec  2 08:07:33 epsqainf5lab15.itg.ti.com login[2117]: USER_PROCESS: 2117 ttys000
Dec  2 08:07:33 epsqainf5lab15.itg.ti.com login[2117]: DEAD_PROCESS: 2117 ttys000

So I'm completely stumped on this. Does anyone have any suggestions how to get this working?

Community
  • 1
  • 1
CMTaylor
  • 11
  • 1

1 Answers1

1

Seems there were two problems with my approach:

  1. The "screen" command only seems to work when you're running it from a command with ancestry to a terminal screen.
  2. If "screen" worked, then it would return. If both "screen" steps worked then the AutoStartScripts.sh would terminate.

My solution, now working fine, was to create two shell scripts:

  • AutoStartDispatcher.sh
  • AutoStartRunProcServer.sh

and then create two .plist files, one pointing to each of the two .sh files:

  • RF.AutoLaunch.Dispatcher.plist
  • RF.AutoLaunch.RunProcServer.plist

Then I went through the "launchctl load <.plist file path>" step for each of the .plist files.

CMTaylor
  • 11
  • 1