I have a script to change the desktop background every so many seconds. Whilst field testing, it didn’t do anything but say Variabe “topTemplate” not defined. Help!
if topTemplate's used is missing value then
set topTemplate's dformat to "f"
set topTemplate's speed to "5"
set topTemplate's dfolder to "Macintosh HD:Users:Fisto:Pictures:Backgrounds:" as alias
display dialog "Variables reset" buttons {"OK"} giving up after 2
end if
set picnum to 1
on idle
tell application "Finder"
repeat
if topTemplate's dformat is "f" then
set dpictures to list folder topTemplate's dfolder as alias without invisibles
set picnumbers to the number of items in topTemplate's dfolder
set dpicture to item picnum of dpictures
set picnum to picnum + 1
else
set dpictures to topTemplate's dpictures
set picnumbers to the number of items in dpictures
set dpicture to item picnum of dpictures
set picnum to picnum + 1
end if
set desktop picture to dpicture
end repeat
end tell
end idle
script topTemplate
property used : missing value
property speed : missing value
property dfolder : missing value
property dformat : missing value
property dpictures : missing value
end script
P.S. My system preferences for desktop and screensaver crash on use. That’s why I’m making this.
GREAT!!! That bit works fine. New problem: My final script won’t use it’s idel handlers.:
script topTemplate
property used : missing value
property speed : missing value
property dfolder : missing value
property dformat : missing value
property dpictures : missing value
property timer : missing value
property buttonlist : missing value
end script
set picnum to 1
if topTemplate's used is missing value then
set topTemplate's dformat to "f"
set topTemplate's speed to "5"
set topTemplate's timer to "4"
set topTemplate's dpictures to {"Macintosh HD:Users:Fisto:Pictures:Backgrounds:BHgandalf1920x1200.jpg"}
set topTemplate's buttonlist to {"Format", "Folder", "Timer"}
set topTemplate's dfolder to "Macintosh HD:Users:Fisto:Pictures:Backgrounds:" as text
display dialog "Variables reset" buttons {"OK"} giving up after 2
end if
tell application "Finder"
activate
end tell
delay 1
on idle
tell application "Finder"
repeat
if topTemplate's dformat is "f" then
set dfoldercon to list folder topTemplate's dfolder
set dpictures to list folder topTemplate's dfolder as alias without invisibles
set picnumbers to (the number of items in dfoldercon)
set dpicture to item picnum of dpictures
set picnum to picnum + 1
else
set dpictures to topTemplate's dpictures
set picnumbers to the number of items in dpictures
set dpicture to item picnum of dpictures as text
set picnum to picnum + 1
end if
set dtarget to (topTemplate's dfolder & dpicture)
set desktop picture to file dtarget
if picnum is the number of items in dpictures then set picnum to 1
delay topTemplate's timer
end repeat
end tell
end idle
set choice to (display dialog "Options:" buttons topTemplate's buttonlist default button 1 giving up after 10)
try
set choice to the button returned of choice
if choice is "Format" then
set dformat to the button returned of (display dialog "Format" buttons {"Folder", "List"} default button 1)
if dformat is "List" then
set topTemplate's dformat to "l"
set topTemplate's buttonlist to {"Format", "List", "Timer"}
else
set topTemplate's dformat to "f"
set topTemplate's buttonlist to {"Format", "Folder", "Timer"}
end if
else if choice is "Timer" then
set topTemplate's timer to the (text returned of (display dialog "Timer:" default answer topTemplate's timer buttons {"OK"} default button 1)) - 1
else if choice is "Folder" then
set topTemplate's dfolder to (choose folder with prompt "Pictures only. No other files or programs/sounds/save file... etc.")
else if choice is "List" then
repeat
set choice to the button returned of (display dialog "List:" buttons {"Add", "Remove", "OK"})
if choice is "Add" then
set topTemplate's dpictures to topTemplate's dpictures & (choose file with prompt "Choose a picture")
else
set remover to (choose from list topTemplate's dpictures)
set topTemplate's dpictures to dpictures of topTemplate without remover
end if
end repeat
end if
end try
repeat
set choice to the button returned of (display dialog “List:” buttons {“Add”, “Remove”, “OK”})
if choice is “Add” then
set topTemplate’s dpictures to topTemplate’s dpictures & (choose file with prompt “Choose a picture”)
else
set remover to (choose from list topTemplate’s dpictures)
set topTemplate’s dpictures to dpictures of topTemplate without remover
end if
end repeat
This is an infinite repeat loop. The script will never exit this. You need an ‘exit repeat’ somewhere to get out of it.
For some reason, this seems to work now. Thanks everyone!
script topTemplate
property dfolder : "Macintosh HD:Users:Fisto:Pictures:Backgrounds:"
property dformat : "f"
property dpictures : {"Macintosh HD:Users:Fisto:Pictures:Backgrounds:BHgandalf1920x1200.jpg"}
property timer : 4
property buttonlist : {"Format", "Folder", "Timer"}
end script
on idle
tell application "Finder"
set picnum to 1
repeat
if topTemplate's dformat is "f" then
set dfoldercon to list folder topTemplate's dfolder
set dpictures to list folder topTemplate's dfolder as alias without invisibles
set picnumbers to (the number of items in dfoldercon)
set dpicture to item picnum of dpictures
set picnum to picnum + 1
else
set dpictures to topTemplate's dpictures
set picnumbers to the number of items in dpictures
set dpicture to item picnum of dpictures as text
set picnum to picnum + 1
end if
set dtarget to (topTemplate's dfolder & dpicture)
set desktop picture to file dtarget
if picnum is the number of items in dpictures then set picnum to 1
delay topTemplate's timer
end repeat
end tell
end idle
set choice to (display dialog "Options:" buttons topTemplate's buttonlist default button 1 giving up after 10)
try
set choice to the button returned of choice
if choice is "Format" then
set dformat to the button returned of (display dialog "Format" buttons {"Folder", "List"} default button 1)
if dformat is "List" then
set topTemplate's dformat to "l"
set topTemplate's buttonlist to {"Format", "List", "Timer"}
else
set topTemplate's dformat to "f"
set topTemplate's buttonlist to {"Format", "Folder", "Timer"}
end if
else if choice is "Timer" then
set topTemplate's timer to the (text returned of (display dialog "Timer:" default answer topTemplate's timer buttons {"OK"} default button 1)) - 1
else if choice is "Folder" then
set topTemplate's dfolder to (choose folder with prompt "Pictures only. No other files or programs/sounds/save file... etc.")
else if choice is "List" then
repeat
set choice to the button returned of (display dialog "List:" buttons {"Add", "Remove", "OK"})
if choice is "Add" then
set topTemplate's dpictures to topTemplate's dpictures & (choose file with prompt "Choose a picture")
else if choice is "Remove" then
set remover to (choose from list topTemplate's dpictures)
set topTemplate's dpictures to dpictures of topTemplate without remover
else
exit repeat
end if
end repeat
end if
end try