Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

apple script daily change desktop background

Posted on 2009-07-03
7
Medium Priority
?
995 Views
Last Modified: 2012-06-27
I am looking to have the following...

*Applescript change my desktop background

*Have the change done daily (per week)

I tend to look at my screens too long sometimes.

I would just have 7 colors jpgs for the script to run from.


I am not a Apple Script guy... just php.

So I am looking at ways to do this automated on startup.


Thanks!
0
Comment
Question by:seaword
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:AGoodKeenMan
ID: 24776392
In leopard this is available in System Preferences -> Desktop, however I suspect it is not in Tiger, so try the following script. Copy and paste the text below into "Applescript Editor", change the pathToImages variable to where ever your folder of images is and save the script where ever you like. Then in iCal setup a new event and set the alarm to run this script once a day.
-- Applescript to randomly change Desktop picture
-- Note does not check if file is an image
 
set pathToImages to "Library:Desktop Pictures:Nature"
 
tell application "Finder"
	if folder pathToImages of startup disk exists then
		try
			set desktop picture to some file in folder pathToImages of startup disk
		on error
			return 0
		end try
	end if
end tell

Open in new window

0
 

Author Comment

by:seaword
ID: 24776917
Thanks, i just want to keep it all in action script though....

I use a different day management software for my work.


I was hoping that you might know of an " IF THEN" statement for applescript.

That way the script could just check the OS date and time.

SO I would have conditionals for the time and days.

That way I could edit the file myself.


0
 
LVL 5

Expert Comment

by:AGoodKeenMan
ID: 24778101
Having an applescript looping all day is not an ideal solution. With ical you can schedule the script to run at a certain time of the day and repeat when ever and as often as you like.
Another idea might be to run the shell script below from a cron job.
You can read more about setting up a cron job here:
http://www.macosxhints.com/article.php?story=2001020700163714
#!/bin/sh -
#
# cron job to run applescript
 
osascript /path/to/script

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:seaword
ID: 24778125
The script would only be run once at startup.

i guess a cron job would work as well...


can you give an example of how I could do an IF THEN conditional in applescript?
0
 
LVL 5

Expert Comment

by:AGoodKeenMan
ID: 24778511
I should have thought of this earlier, you can run a script at login. Just add the script below to the login items for your user account.

You can edit theHours and theMinutes variables to suit your timing requirements. (currently set to 1:30am)


-- Applescript to randomly change Desktop image once a day
-- Does not check if file is an image
 
property lastTimeRun : ""
set pathToImages to "Library:Desktop Pictures:Nature"
set theHours to 1 -- must be less then 24
set theMinutes to 30 -- must be less than 60
 
tell application "Finder"
	set theDate to current date
	
	-- Check if the script has already been run today
	set today to date string of theDate
	if lastTimeRun is not today then
		
		--Check to see if it is time to run the script today
		set currentHours to (hours of (theDate))
		set currentMinutes to (minutes of (theDate))
		if (currentMinutes e theMinutes) and (currentHours e theHours) then
			set lastTimeRun to today
			if folder pathToImages of startup disk exists then
				try
					set desktop picture to some file in folder pathToImages of startup disk
				on error
					return 0
				end try
			end if
		end if
	end if
end tell

Open in new window

0
 
LVL 5

Accepted Solution

by:
AGoodKeenMan earned 2000 total points
ID: 24778515
It looks like line 19 has some encoding problems, replace it with the one below (hopefully).
if (currentMinutes >= theMinutes) and (currentHours >= theHours) then

Open in new window

0
 

Author Closing Comment

by:seaword
ID: 31599715
Thank you for taking time to help me.

I actually looked into 10.5.6 and the improvements they made to scripting.

The bridge (python / C / JS / ruby) is huge.

Thank again.  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn different types of Android Layout and some basics of an Android App.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question