Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron job reasoning - use a plist instead? #6

Closed
anon1y4012 opened this issue Jun 11, 2018 · 12 comments
Closed

Cron job reasoning - use a plist instead? #6

anon1y4012 opened this issue Jun 11, 2018 · 12 comments

Comments

@anon1y4012
Copy link

anon1y4012 commented Jun 11, 2018

Is there a particular reason you suggest using a cron job to run the script at an interval? Cron is typically not used anymore, in favor of launchd. Launchd allows the script to execute while the system is asleep, and on wake. You can also specify the interval without using a nano editor to change it. I've included an example plist with a 10 minute interval and a run on wake parameter as well. This should be placed in the LaunchDaemon folder if you want it to run whether you're logged in or not, or LaunchAgents if you only want it running while logged in.

You'll need to use a text editor to specify the path of the script inside the plist, then save it as wallpaper.plist instead of .txt. Once inside the Library/LaunchDaemons folder, you'll use the terminal command "launchctl load /PATH/TO/PLIST" to load the launchd file.

wallpaper.txt

Let me know what you think, the script works great so far!

Edit: More specific instructions.

@Dniel97
Copy link

Dniel97 commented Jun 11, 2018

So, I renamed your script to wallpaper.plist edited the username inside and placed it in /Library/LaunchDaemons/ changed the owner to root and restarted. After entering: "launchctl load /Library/LaunchDaemons/wallpaper.plist" it finally worked.

@anon1y4012
Copy link
Author

Yes, I should've been more specific with my instructions. What you did is correct, you can also use launchctl unload ... to disable it.

@Dniel97
Copy link

Dniel97 commented Jun 12, 2018

The only problem is that the wallpaper files a from my user account and when I place your plist inside /Library/LaunchDaeomons/ it won't work, but if I place them inside/User/Username/Library/LaunchAgents your script works just fine.

@kush-agra
Copy link
Owner

@john2691 my main purpose was to create the main script and suggested a cron job as it was simple to set up even for someone a little new to all of this, I did suggest using a plist and launchd just above the P.S for those who know what they are doing, launchd is definitely the better option and replaces cron, just thought using cron would be easier but we could move to a plist that is better, I'm not too familiar with those I did try it out earlier when I was building it, is there a way to set a universal plist so the user doesn't have to specify the absolute path?

I would like to use the plist method too

@anon1y4012
Copy link
Author

@Dniel97, that's certainly strange, it runs on my machine without issue. I'll have to look into it. @kush-agra so long as they're putting the files in the /Pictures/Wallpapers folder, I think ~/Pictures/Wallpapers should suffice in the .plist file. I can experiment with it.

@Dniel97
Copy link

Dniel97 commented Jun 12, 2018

@john2691 It works just fine in /Users/USERNAME/Library/LaunchAgents, but I don't know why it isn't working in /Library/LaunchDaemons/

@kush-agra
Copy link
Owner

oh nice, surely let me know @john2691 after experimenting and I'll set it up for a plist instead that'd be great

@kush-agra kush-agra changed the title Cron job reasoning? Cron job reasoning, use a plist instead Jun 12, 2018
@kush-agra kush-agra changed the title Cron job reasoning, use a plist instead Cron job reasoning? use a plist instead Jun 12, 2018
@kush-agra kush-agra changed the title Cron job reasoning? use a plist instead Cron job reasoning? use a plist instead? Jun 12, 2018
@kush-agra kush-agra changed the title Cron job reasoning? use a plist instead? Cron job reasoning - use a plist instead? Jun 12, 2018
@anon1y4012
Copy link
Author

@kush-agra It looks as though the absolute path is required, since it's an AppleScript and not a shell script. Shell scripts are able to be called in a plist using the ./ method, but not AppleScripts. I'll try to think of an elegant way to make that easy for users, but so long as cron isn't causing issues it's not that important.

@kush-agra
Copy link
Owner

exactly my thought process, we could use a shell script to call the AppleScript?

@anon1y4012
Copy link
Author

That's one solution, I'm actually writing a script right now that will get the current username, create a proper .plist file and put it in the correct folder. Either way should be pretty user friendly.

@anon1y4012
Copy link
Author

Ok, all done. Give this a try on your machine and let me know how it works. You should be able to unzip, double click and let it go. It's only zipped because GitHub doesn't allow .command files.
Plist Generator.zip

@kush-agra
Copy link
Owner

Seems to be working great and is easier, I'll add it to master :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants