@cdenesha Could you please elaborate?
@Buraq I was wrong about the space, per the next post in the thread. :)
UPDATE:
I managed to load the Agent. The problem was with wrong extension. Now if I launchctl load -w MyAgent nothing happens, and when I run the same command again I get this: service already loaded.
Both times the actual script is not called.
This is how I'm calling it in the launch agent:
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/Users/buraqalsmadi/Library/LaunchAgents/DataScience/Datascience_High_Sierra.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
@Buraq I'm not sure if it's necessary to put the sh -c
in front of your script path. If you make sure the script has the executable bit set (run chmod +x /Users/buraqalsmadi/Library/LaunchAgents/DataScience/Datascience_High_Sierra.sh
against it) then simply putting in the path to the script should run it when the agent is loaded. You usually only need to put in things like sh
if you want to use a different interpreter than specified in the script or if it's not set as executable. I would try removing the <string>sh</string> <string>-c</string>
section and trying again.
But one other thing. If launchctl is saying the plist is already loaded, you'll want to make sure to unload it first before trying to load it again. Just use launchctl unload
on it.
if you see yourself doing more of this in the future, you may want to check out outset
- Install outset
- Place script in applicable folder
- Create .pkg with composer for mass deploy
- Beer/Pub
@mm2270 I have removed <string>sh</string> <string>-c</string> and tried again, no luck!
The script is executable.
It seems what matter I do, and even when the launch agent loads, it doesn't call the script
I needed the logged in user to run something similar from Self Service; thanks to tips here ended up using something like this in a script:
sudo -u $3 -i /path/to/binary --parameter $3 --destination /Users/$3/Desktop/$3 --verbose
@swaroopmj You need the -l flag for your su command, and the pound sign for your shebang line. Try this:
#!/bin/bash
currentuser=$(/bin/ls -la /dev/console | /usr/bin/cut -d ' ' -f 4)
su -l $currentuser -c "defaults read /Users/$currentuser/Library/Preferences/com.apple.dock | grep corner"
Then chmod/chown as needed.
Fairly old thread but after trying numerous ways to do this, yours ended up working for me.
For hiding the bluetooth icon in the top bar:
defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist Bluetooth -int 24
Above doesn't work as sudo or admin, only works as logged in user.
#!/bin/bash
currentuser=$(/bin/ls -la /dev/console | /usr/bin/cut -d ' ' -f 4)
su -l $currentuser -c "defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist Bluetooth -int 24"
The above is working in 12.2 Monterey.