Using launchd to run script once a day when logged in

I’m in the situation where I would like to run a script only once per day when I open my MacBook.

I guess I could have the script note the date it was last run, and have it reject when run on the noted day.. however I was hoping launchd had some fancy mechanics to avoid this!

After googling a bit about crontab and offline schedules, I learned about anacron which unfortunately isn’t available on macOS — however they all recommended launchd instead.

TL;DR: say I have a script I want to run only once a day. I can schedule it for 6, 8 or 10 in the morning, however there is no guarantee that I will have my laptop open (or even booted into macOS) at this time. What’s the trick for scheduling an event that will happen once in a certain timespan, despite it not being online for all of it?

launchd – Alter ulimit for Terminal without changing kernel parameters

Note: I am looking for an answer for Catalina and for Big Sur. The commands below were run on Catalina. Most related questions and answers are for older versions of macOS which work a bit differently, but even then I have not found an exact answer to my question.

As I explained here, I want to increase the ulimit -n (max open files) for the Terminal program when launched from the Finder or when automatically started when logging in as part of restoring open windows. Even though I have performance mode turned on, the default ulimit -n is only 256, and most Terminal windows take up 2 file slots: 1 for the shell and one for the “Saved Application State” file, limiting me to around 128 windows, which sometimes is not enough.

The only way I have found to change the ulimit for the Terminal is via

sudo launchctl limit maxfiles <soft-limit> <hard-limit>

I would like to set the soft limit to something bigger than 256 but still reasonably small, like 512 or 1000. I would like to leave the hard limit unlimited. Unfortunately, I found out that you cannot set the hard limit to “unlimited”, but that is OK, I can set it to an appropriately high number. I checked the kernel limits (remember, I have performance mode enabled):

$ sysctl kern.maxfilesperproc kern.maxfiles
kern.maxfilesperproc: 600000
kern.maxfiles: 1200000

It seemed reasonable to me to set the hard limit to kern.maxfilesperproc, so I ran

sudo launchctl limit maxfiles 999 600000

at which point several programs immediately crashed. I found that this did not just set the ulimit, it also set the kernel parameters, and not the way I expected:

$ sysctl kern.maxfilesperproc kern.maxfiles
kern.maxfilesperproc: 999
kern.maxfiles: 600000

So programs with more than 1000 files open crashed. Obviously, those programs knew they were going to need to have a lot of files open and adjusted their resource limits appropriately, which is fine, and I need to keep that. On the other hand, programs like Terminal can get into loops that consume resources until they run out, so I want to keep soft limits for those programs low.

I tried setting ulimit in /etc/bashrc and /etc/zshrc but those only affect their respective shells, not commands like Terminal that are launched by the Finder/launchd.

Is there some way I can adjust the default soft limit for number of open files (ulimit -Sn, setrlimit()) for Terminal (or system-wide) without also changing the kernel parameter kern.maxfilesperproc (sysctl)?

Launchd job doesn’t run at specified interval

I had a launchd job where the StartInterval is set to 10800 (seconds), however, the job actually ran at a rather short interval like 5 seconds, and I couldn’t figure out why.

Here’s the job definition:
(requires terminal-notifier, which can be installed via brew install --cask terminal-notifier

<?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>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>launchd.test</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/terminal-notifier</string>
        <string>-message</string>
        <string>from launchd</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/launchd_interval_test.log</string>
    <key>StandardOutPath</key>
    <string>/usr/local/var/log/launchd_interval_test.log</string>
    <key>StartInterval</key>
    <integer>10800</integer>
</dict>
</plist>

How do I debug the interval issue?

launchd – pfctl: Duplicate signature for

launchd – pfctl: Duplicate signature for – Ask Different

launchd – How do I unset configured by launchctl?

launchd – How do I unset configured by launchctl? – Ask Different

mac – lsd and tccd hogging CPU, launchd getting killed often

The last couple of days, my Mac (OS 10.14.6 Mojave) has had two daemon processes running hard and hot: lsd (launch service) and tccd (which apparently manages which apps have permission to access contacts and maybe other things).

Short summary: These processes are perpetually hogging the CPU, and certain core functions that should be almost instantaneous, instead take minutes.

Details:

Here are a couple of screenshots showing CPU usage by these two processes. Note the wavy line in the graph.

screenshot of Activity Monitor

screenshot 2 of Activity Monitor

Before someone marks this as a duplicate, here are some other similar questions and notes as to why they don’t solve my problem:

  • tccd stuck and taking up lots of cpu The solution for this question was to remove XCode’s access to Contacts, via System Preferences → Security & Privacy → Privacy → Contacts. However, on my machine there are no apps listed under Privacy → Contacts, neither XCode nor anything else.

  • This blog post about removing the TCC.db database is helpful. But I have removed that database and it didn’t solve the problem.

  • This question about lsd and tccd only applies to Mac startup, but in my case, both processes continue running hot and heavy for hours after the machine has booted.

  • /usr/libexec/lsd using 100% of CPU recommends removing any .app files that are open by the lsd process. But running pgrep -u 503 lsd | xargs lsof -p doesn’t show any .app files.

  • What is the “lsd” process on OS X, and why is it using so much CPU power? seems similar to the problem I have, but aside from referencing the above post, it just addresses a specific error that the asker was seeing, which I’m not seeing.

  • mdworker gets killed 9 by mds and lsd goes high cpu seems to be very close to the problem I’m seeing. The OP there mentioned TimeMachine, and on my Mac, TimeMachine has been having a hard time successfully backing up. However, that question has no answer.

Operations that take a long time on my machine, sometimes literally minutes:

  • Apple menu > About this Mac: The info window can take minutes to appear.

  • Launcher: when I press the Option+Cmd+L shortcut, the Launcher UI appears immediately, but when I start typing, it can take minutes for any of the letters I typed to appear on the screen.

  • Launching apps from the Applications folder, either by double-clicking, or by selecting and pressing Cmd+O.

  • Links: If I click on a link in email, it can take minutes for the web page to open in the browser, even though the browser itself is responding normally in regard to clicking on links.

The delay in launching apps by itself is a major productivity killer. I assume that problem, at least, is related to the lsd process running so hot and heavy.

I have of course rebooted (several times), but the problem keeps coming back.

I found the following in system.log in Console, showing that launchd keeps getting SIGKILLed by mds:

May  5 17:27:25 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:27:26 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11719)): Service exited due to SIGABRT
May  5 17:28:04 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0C000000-0000-0000-0000-000000000000(11748)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:28:06 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:28:06 Lars-2015-MBP kcm(11759): DEPRECATED USE in libdispatch client: Setting timer interval to 0 requests a 1ns timer, did you mean FOREVER (a one-shot timer)?; set a breakpoint on _dispatch_bug_deprecated to debug
May  5 17:28:12 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11755)): Service exited due to SIGABRT
May  5 17:28:50 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0C000000-0000-0000-0000-000000000000(11768)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:28:53 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0F000000-0000-0000-0000-000000000000(11761)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:28:56 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0F000000-0000-0000-0000-000000000000(11771)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:29:08 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:29:09 Lars-2015-MBP kcm(11778): DEPRECATED USE in libdispatch client: Setting timer interval to 0 requests a 1ns timer, did you mean FOREVER (a one-shot timer)?; set a breakpoint on _dispatch_bug_deprecated to debug
May  5 17:29:14 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.06000000-0000-0000-0000-000000000000): Service only ran for 4 seconds. Pushing respawn out by 6 seconds.
May  5 17:29:31 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11769)): Service exited due to SIGABRT
May  5 17:29:52 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.02000000-0000-0000-0000-000000000000(11783)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:02 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.04000000-0000-0000-0000-000000000000(11784)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:03 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.06000000-0000-0000-0000-000000000000(11786)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:07 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0C000000-0000-0000-0000-000000000000(11797)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:08 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.02000000-0000-0000-0000-000000000000(11799)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:08 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.10000000-0000-0000-0000-000000000000(11798)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:16 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0F000000-0000-0000-0000-000000000000(11802)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:30:27 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:30:28 Lars-2015-MBP kcm(11812): DEPRECATED USE in libdispatch client: Setting timer interval to 0 requests a 1ns timer, did you mean FOREVER (a one-shot timer)?; set a breakpoint on _dispatch_bug_deprecated to debug
May  5 17:30:36 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11804)): Service exited due to SIGABRT
May  5 17:31:14 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0C000000-0000-0000-0000-000000000000(11819)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:31:20 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:31:22 Lars-2015-MBP kcm(11828): DEPRECATED USE in libdispatch client: Setting timer interval to 0 requests a 1ns timer, did you mean FOREVER (a one-shot timer)?; set a breakpoint on _dispatch_bug_deprecated to debug
May  5 17:31:32 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11824)): Service exited due to SIGABRT
May  5 17:31:47 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:32:19 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0C000000-0000-0000-0000-000000000000(11839)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:32:26 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0F000000-0000-0000-0000-000000000000(11843)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:32:31 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:32:36 Lars-2015-MBP kcm(11853): DEPRECATED USE in libdispatch client: Setting timer interval to 0 requests a 1ns timer, did you mean FOREVER (a one-shot timer)?; set a breakpoint on _dispatch_bug_deprecated to debug
May  5 17:32:47 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11845)): Service exited due to SIGABRT
May  5 17:33:23 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.mdworker.shared.0C000000-0000-0000-0000-000000000000(11859)): Service exited due to SIGKILL | sent by mds(85)
May  5 17:33:37 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.imfoundation.IMRemoteURLConnectionAgent): Unknown key for integer: _DirtyJetsamMemoryLimit
May  5 17:33:40 Lars-2015-MBP kcm(11869): DEPRECATED USE in libdispatch client: Setting timer interval to 0 requests a 1ns timer, did you mean FOREVER (a one-shot timer)?; set a breakpoint on _dispatch_bug_deprecated to debug
May  5 17:33:50 Lars-2015-MBP com.apple.xpc.launchd(1) (com.apple.backupd(11864)): Service exited due to SIGABRT

And I found diagnostic files saying that lsd and tccd had been exceeding limits:

Of course there’s much more in these diagnostic files, but I don’t really know how to identify the cause of the problem, out of the flood of data. Click on the links above to see the files on pastebin.

Stop malware from being executed by launchd

I’ve got this program running on my computer, /var/root/Library/Application Support/.SectionChannel.dp/SectionChanneldd, which Norton has identified as the malware OSX.Malcol. However, Norton has been thoroughly unhelpful in doing anything about it. I’ve tried deleting the file as well as sending a SIGKILL to the running process. However, it keeps restarting.

Digging further via Activity Monitor, I discovered that the parent process is launchd. How can I figure out what is causing launchd to execute this program and stop it? Resetting my computer does not fix the issue.

launchd – How to see which services were unloaded using “launchctl unload -w” on macOS?

I ran the following to disable Adobe background services.

BUNDLE_IDENTIFIER_PREFIX="com.adobe"
sudo launchctl unload -w /Library/{LaunchAgents,LaunchDaemons}/$BUNDLE_IDENTIFIER_PREFIX*.plist
launchctl unload -w ~/Library/LaunchAgents/$BUNDLE_IDENTIFIER_PREFIX*.plist

According to this answer, using launchctl unload -w adds services to override database.

The override database is obscure. How can I see which services were unloaded using “launchctl unload -w” on macOS?

DreamProxies - Cheapest USA Elite Private Proxies 100 Cheapest USA Private Proxies Buy 200 Cheap USA Private Proxies 400 Best Private Proxies Cheap 1000 USA Private Proxies 2000 USA Private Proxies 5000 Cheap USA Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Proxyti.com Buy Quality Private Proxies