3

I made an app (tested it works) and I want to make it run every day at midnight. Here is my PLIST file:

EDIT: after using @user3439894's code here is what I put in my PLIST

<?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.example.exampled</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/open</string>
        <string>-a</string>
        <string>/Applications/Calculator.app</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Hour</key>
            <integer>0</integer>
            <key>Minute</key>
            <integer>0</integer>
        </dict>
    </array>
</dict>
</plist>

When I run it using sudo launchctl load /Users/fbisurveillancevan/Desktop/LaunchMessageText.plist, it returns nothing. When I try again, it returns launchctl: already loaded The daemon/agent appears to be loaded, but does not run

10
  • 1
    You need to read the manual pages for launchctl and launchd.plist as LaunchAgents and LaunchDaemons have specific directories (folders) they need to be in. Also you can't run an app directly like that. For example, if in Terminal you tried to execute e.g. /Applications/Calculator.app it would return e.g. -bash: /Applications/Calculator.app: is a directory however if you used e.g. open -a /Applications/Calculator.app it would open Calculator. You might even have to use a shell script to launch your app with the open command. Apr 11, 2020 at 3:41
  • @user3439894 so the problem is that its in the wrong folder Apr 11, 2020 at 3:47
  • RE: "so the problem is that its in the wrong folder" -- Yes, that's one issue, but not the only issue. I already told you what another issue it using Calculator as the example app. --- Another issue, I forgot to mention, is typically the Label key is the same name as the .plist file sans the extension. I'd also would place the app in /Applications not on your Desktop. Apr 11, 2020 at 4:00
  • What do you mean by "Task Manager" -- that's generally a Windows program; I've never seen a Mac version. Also, are you trying to set this up as a Launch Agent (runs as the logged-in user), or a Launch Daemon (runs as root, independent of user logins). Apr 11, 2020 at 4:58
  • @GordonDavisson By task manager i mean Activity monitor, and I want it to be a launchAgent Apr 11, 2020 at 16:12

1 Answer 1

5

In addition to the comments I've made to your OP, use this example to fix the issues you are having.

  • Note: This was done under macOS High Sierra and if using macOS Catalina there are some changes to the example, which are detailed is a note further below.

As a test, in Terminal, I executed the following commands:

cd ~/Library/LaunchAgents
touch com.example.exampled.plist
open -e com.example.exampled.plist

Copy and paste the following example PLIST XML code into the opened com.example.exampled.plist file, setting the StartCalendarInterval for a few minutes from now, and then save and close it.

<?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.example.exampled</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/open</string>
        <string>-a</string>
        <string>/Applications/Calculator.app</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Hour</key>
            <integer>0</integer>
            <key>Minute</key>
            <integer>0</integer>
        </dict>
    </array>
</dict>
</plist>


Back in Terminal, execute:

launchctl load com.example.exampled.plist

Now Calculator will open at the set time, which is set using 24 Hour time, e.g 0 through 23 for the Hour key.


macOS Catalina Notes:

  • In a clean install of macOS Catalina, ~/Library/LaunchAgents doesn't exist by default. Use the following command before cd ~/Library/LaunchAgents:

    mkdir -p ~/Library/LaunchAgents
    
  • Due to changes made by Apple in macOS Catalina the fully qualified pathname for the Calculator is: /System/Applications/Calculator.app

Change:

<string>/Applications/Calculator.app</string>

To:

<string>/System/Applications/Calculator.app</string>

Or as an alternative, just use:

<string>Calculator</string>
  • Both methods work.

Additional testing was done with an application bundle (myApp.app) created by me, saved in /Applications on macOS Catalina, and the following values worked for me:

<string>/Applications/myApp.app</string>

Or:

<string>myApp</string>

Note: The use of sudo is required when dealing with agents and daemons that are in the designated locations other then ~/Library/LaunchAgents in order to create, modify, change permissions to make read-only, delete, etc. the XML Plist file itself. Also note that when using the launchctl command for daemons, sudo may be required in some cases, however do not use sudo to load agents with launchctl, as it will load them as a daemon.

To review the manual pages, in Terminal, use man command where command is the commands name, e.g. man launchctl, or to more easily read the manual pages, just type the commands name and right-click on it selecting: Open man Page

If you are going to use Launch Agents and Launch Daemons, I highly recommend you read the manual pages for launchctl, launchd.plist and launchd.


Per the manual pages for launchctl and launchd.plist the PLIST files for Launch Agents and Launch Daemons belong in specific directories:

FILES
    ~/Library/LaunchAgents          Per-user agents provided by the user.
    /Library/LaunchAgents           Per-user agents provided by the administrator.
    /Library/LaunchDaemons          System-wide daemons provided by the administrator.
    /System/Library/LaunchAgents    Per-user agents provided by OS X.
    /System/Library/LaunchDaemons   System-wide daemons provided by OS X.

There is also an example xml property lists file at the end of the manual page forlaunchd.plist.

22
  • 1
    @FBI Surveillance Van, Sorry, I accidentally left off the closing </plist> tag when I copied and pasted it. Please see the updated answer. Apr 11, 2020 at 16:33
  • 1
    @FBI Surveillance Van, Your title says "Launchd wont appear in task manager" and I assume you really mean Activity Monitor. What isn't appearing in Activity Monitor? launchd most certainly appears there, it is after all the parent of all the processes, sans the kernel_task as launchd is a child of it. If your looking for e.g. com.YourUser.RunMyCode you'll not see it there because it's not supposed to show there! If you want to see all of the launchctl jobs loaded into launchd then use launchctl list, or about a specific job, use e.g. launchctl list com.example.exampled. Apr 13, 2020 at 5:38
  • 1
    @FBI Surveillance Van, Let me ask you this... If you follow the directions in my answer verbatim, and I do mean explicitly and specifically as the directions are written, is Calculator launched at the designated time, the time being just a minute or two from the current time before loading it? If yes, then if you use launchctl to stop and unload the com.example.exampled.plist to edit in the real app you want to use and adjust the time again a few minutes from now to test, save it and load it again with launchctl load com.example.exampled.plist, does it work? Apr 13, 2020 at 18:47
  • 1
    @FBI Surveillance Van, This was doe and tested under macOS High Sierra. I'll test this in a while under macOS Catalina and see if I run into any issues. Apr 14, 2020 at 18:33
  • 1
    @user3439894 Thanks for the continued help. So glad that it works now. I hope that more people will benefit from this 😃. Apr 14, 2020 at 23:12

You must log in to answer this question.

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