I am using MAC OSX 10.6.8.
I would like to apply a script that copy a backup file when I find there is a file named temp.txt.
Here is my plist in /Library/LaunchAgents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.lion.backupfile</string>
<key>ProgramArguments</key>
<array>
<string>/Users/lion/q_backup.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Users/lion/temp.txt</string>
</array>
</dict>
</plist>
I find the script only be excuted when file being removed or modified.
How could I excute the script when there is a file exist in the path?
There is no such key in launchd.plist.
WatchPaths will work if any one of the listed paths are modified.
QueueDirectories will run your script whenever there's a file in that directory.
Related
I have a launch daemon plist that runs a python script. The problem is that it is unable to run the script because it does not have access to python.
I am trying to make a launch daemon to change mac address (https://github.com/feross/SpoofMAC)
Here is the plist file in /Library/LaunchDaemons:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>MacSpoof</string>
<key>ProgramArguments</key>
<array>
<string>/Users/username/.asdf/shims/spoof-mac.py</string>
<string>randomize</string>
<string>en0</string>
</array>
<key>StandardOutPath</key>
<string>/Users/username/Projects/MAC/out.log</string>
<key>StandardErrorPath</key>
<string>/Users/username/Projects/MAC/err.log</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The Error Log reads:
No version is set for command spoof-mac.py
Consider adding one of the following versions in your config file at
python 3.11.1
My tool_version does include Python, how can I make this work?
Okay, I kinda got it working. I moved the plist file from /Library/LaunchDaemons to /Library/LaunchAgents and it works because LaunchAgents run after the user is logged in. It's not exactly what I wanted, but it works.
I am trying to integrate BullsEye 8.14.0 with Xcode 10.12. Following are the steps that I followed:
mkdir -p $HOME/Library/LaunchAgents
2.Create the file $HOME/Library/LaunchAgents/BullseyeCoverage.plist with contents like below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>BullseyeCoverage</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>COVFILE</string>
<string>path</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Path I have given as $HOME/Desktop/BEC/test123.cov and also tried with Users/myUserName/Desktop/BEC/test123.cov
Add an export command like shown below to the file $HOME/.bash_profile.
export COVFILE=path
Added export PATH=$PATH:/Applications/BullseyeCoverage/bin, in .bash_profile as the first entry.
Then built the xcode project as usual.
Followed the document https://www.bullseye.com/help/tool-xcode.html, in short.
But after doing all this, I should be seeing a test123.cov file generated after the successful build with all the APIs listed, which I couldn"t see.
Am I missing anything?
I built a job by Automator to clear the downloads folder and empty the trash. When i start the created app by double click, it starts correctly. But it has to be transferred to other computer in our company and i dont want to give the user the job to launch the app.
So i created this LaunchAgent script to start the app.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.herpag.aufraeumen.plist</string>
<key>ProgramArguments</key>
<array>
<string>/Users/hansthiele/Applications/Aufraeumen.app</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>45</integer>
<key>Hour</key>
<integer>13</integer>
</dict>
</dict>
</plist>
My problem is now, that the console tells me that the job is started, but nothing happens. The downloads are not cleared and the trash is still full. Also the error.log is empty.
There are 2 issues:
The Label argument must be specified without the .plist extension.
The path must represent the executable rather than the application container. In case of an Automator app the executable is named Application Stub (unlike Applet in an AppleScript app). It's assumed that hansthiele is the real short username of the current user.
Try
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.herpag.aufraeumen</string>
<key>ProgramArguments</key>
<array>
<string>/Users/hansthiele/Applications/Aufraeumen.app/Contents/MacOS/Application Stub</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>45</integer>
<key>Hour</key>
<integer>13</integer>
</dict>
</dict>
</plist>
I want to rsync my /var/repo backup to a remote machine when it changes.
I made a ssh key pairs to make my machine can ssh login to remote without password(ignore details).
I added a file com.ph.rsync2.plist in ~/Library/LaunchAgents.
The content is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ph.rsync2.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/rsync</string>
<string>-avz</string>
<string>--rsh=ssh</string>
<string>/var/repo</string>
<string>flora#192.168.19.28:/var/ph_backups/</string>
</array>
<key>WatchPaths</key>
<array>
<string>/var/repo</string>
</array>
</dict>
Then I launchctl load com.ph.rysnc2.plist.
When /var/repo has any change, it will trigger rsync to work
but I always get the error log in Console.app
It reads like
11/3/15 2:15:26.399 PM com.apple.xpc.launchd[1]:
(com.ph.rsync2.plist) Service only ran for 1 seconds. Pushing respawn out by 9 seconds.
And I tried to move the rsync commands to a script, then let launchd exec my script. but it's still the same
I can't figure out which part of settings make all these fail.
Anyone can give me a clue?
Comments will mess up the formatting, so I'll post how to setup the StandardErrorPath key as an answer.
Modify your job definition like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ph.rsync2.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/rsync</string>
<string>-avz</string>
<string>--rsh=ssh</string>
<string>/var/repo</string>
<string>flora#192.168.19.28:/var/ph_backups/</string>
</array>
<key>StandardErrorPath</key>
<string>/tmp/com.ph.rsync2.plist.stderr</string>
<key>WatchPaths</key>
<array>
<string>/var/repo</string>
</array>
</dict>
</plist>
Check the file /tmp/com.ph.rsync2.plist.stderr after reloading and starting the job.
I need a way to automatically do a vagrant up command inside my directory /Users/user/Dropbox/Development/Homestead
Does anyone know how this can be achieved?
You can write an automator application (i.e. workflow) and in that application have it run the shell script with your desired vagrant command. Then go to System Preferences -> Accounts -> Login items and add that application as a login item.
With a LaunchD item. Put a file containing this in your /Library/LaunchDaemons directory:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UserName</key>
<string>user</string>
<key>Label</key>
<string>org.xyzzy.vagrantsrc</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
</dict>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/vagrant</string>
<string>up</string>
</array>
<key>RunAtLoad</key><true/>
<key>UserName</key><string>jenkins</string>
<key>WorkingDirectory</key><string>/Users/user/Dropbox/Development/Homestead</string>
</dict>
</plist>
It needs to be owned by root and called something.plist