kush-agra / Dynamic_Walls

Replicating macOS Mojave's dynamic wallpaper feature
https://github.com/kush-agra/Dynamic_Walls-app/
42 stars 3 forks source link

Cron job reasoning - use a plist instead? #6

Closed anon1y4012 closed 6 years ago

anon1y4012 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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

anon1y4012 commented 6 years ago

@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 commented 6 years ago

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

anon1y4012 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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