0

(sorry if this is a bad question. I am new to apple coding)

I want to run a .scpt file at a specific time, once a day, every day using launchd (if there is a better way please tell me) I am running macOS Catalina, and can make it a .app

How would I use launchd to run this? Please give me the complete code/steps to run this as I have no experience with Html/Css/Plist files.

Can somebody post a code template? I have never used PLIST files

Seamus
  • 4,547
  • 1
    Suggest you read the manual pages for launchd and launchd.plist as well as for launchctl. In Terminal, use e.g. man $command where $command is one of the previously mentioned commands. – user3439894 Apr 07 '20 at 23:38
  • 1
    Welcome to Ask Different :) In addition to waht @user3439894 recommended, you should also consider going the online guides here and here. That should help you with your query or phrase a more focused question. – Nimesh Neema Apr 07 '20 at 23:39
  • @user3439894 I didn't think of reading the manual page. Thanks! – FBI Surveillance Van Apr 07 '20 at 23:40
  • @user3439894 how do you get out of the manual page in terminal? – FBI Surveillance Van Apr 07 '20 at 23:41
  • 1
    Type the character q to get back to a command prompt. BTW if you just type the $command name you can right-click on it and select Open man Page, which will give you a better way to review and then just close the window normally. – user3439894 Apr 07 '20 at 23:46
  • @NimeshNeema do I need to make the .Scpt file into a .app? – FBI Surveillance Van Apr 08 '20 at 01:05
  • 1
    RE: "Can somebody post a code template? I have never used PLIST files" -- There. is a sample .plist file at the end of the launchd.plist manual page! – user3439894 Apr 08 '20 at 01:09

1 Answers1

2

launchd manages the daemon(s) that ultimately run your job (in your case an scpt). But in a setup similar to the "man behind the curtain" in The Wizard of Oz you don't talk directly to launchd. Instead, you will prepare a .plist (property list) file that will be parsed by launchctl, and only then presented to launchd for action.

I did this (manually created a .plist file) a while ago, and wrote up a brief "how-to" that you can find on this GitHub page. My experience was that writing an error-free .plist file from scratch is arcane and error-prone, but I'm sure one gets better with practice!

Note that this example was done on Mojave - not on Catalina. And as with various other things, Apple has made access to launchd (the man behind the curtain) more difficult in the name of security. In other words, the sample from my GitHub page runs successfully on Mojave, but it will not run on Catalina without hacking around Apple's more restrictive security measures.

Which brings me to the point of this: Instead of manually creating a .plist file, you may wish to consider using a third-party tool called LaunchControl. For Catalina, 'LaunchControl' now includes a "helper tool" called fdautil that simplifies cooperation with Apple's security mechanisms. I've used it successfully for two UserAgent jobs that run under launchd on Catalina.

Seamus
  • 4,547