Re: name of the current desktop picture
Re: name of the current desktop picture
- Subject: Re: name of the current desktop picture
- From: Robert Poland <email@hidden>
- Date: Mon, 12 May 2014 15:52:02 -0600
This works, most of the time in Mavericks. Occasionally skips a Space.
(* Set_Spaces - 11/25/13 - By R Poland 1/5/13 - Added nullPicture Help from Yvan
*)
# pick a new background image
set nullPicture to "~/Pictures/APOD ƒ/nullPicture.jpg" # Temp blank image
set ThePicture to choose file
delay 1
tell application "System Events" to set the_size to size of disk item (ThePicture as text)
set pictureDelayTime to (the_size / 100000 as integer) / 20
# log "ThePicture = " & ThePicture
# Find out how many spaces/desktops you have.
# I moved this instruction out of the tell application block to get rid of
# non fatal error -1708 issued by the call to OSAX
((path to system folder as text) & "Library:PreferencePanes:Keyboard.prefPane:")
tell application "System Preferences"
set switchTo_loc to localized string "Switch to Space 1" from table "DefaultShortcutsTable" in bundle file result
end tell
delay 1 # time to switch Spaces if required
# Quick and dirty code supposed to treat every languages available
if switchTo_loc contains "1" then
set switchTo_loc to item 1 of my decoupe(switchTo_loc, "1")
else
# Arabian or languages behaving the same
set switchTo_loc to my recolle(items 1 thru -2 of my decoupe(switchTo_loc, space), space)
end if
tell application "System Preferences"
activate
reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
end tell # application "System Preferences"
delay 1
tell application "System Events"
activate
tell process "System Preferences"
tell window 1 to tell splitter group 1 of tab group 1
tell table 1 of scroll area 1
# Code identifying the entry entitled "Mission Control"
set theRow to 0
repeat with r from 1 to count rows
if name of first static text of row r is "Mission Control" then
set theRow to r
exit repeat
end if
end repeat
if theRow > 0 then
# select the correct row (2 in French, 3 in English)
select row theRow
else
error "There is no Mission Control entry !"
end if
end tell
set numSpaces to count (UI elements of rows of outline 1 of scroll area 2 whose name begins with switchTo_loc)
end tell # "Keyboard"
end tell # process "System Preferences"
tell application "System Preferences" to quit
delay 1
key code 18 using control down # Move to desktop 1
delay 1
# ************************************
repeat with i from 1 to numSpaces + 1
delay 1
tell application "System Events"
set backGroundPath to (picture of current desktop) # returns an Unix path
set backGroundName to name of disk item result
end tell -- System Events
if backGroundName ≠ ThePicture then
tell current desktop
set picture to nullPicture # wipe out current Picture
delay 1
set picture to ThePicture
delay pictureDelayTime # set delay by image size
tell me to beep # Edited this way to get rid of non fatal error -1708
delay 0.5
end tell
end if -- if backGroundName ≠ thepicture
# switch to the next desktop
# *Note:* Set your keyboard shortcut for "next desktop" if it's different
key code 124 using control down # ^→
delay 1
end repeat # 1 to numSpaces
delay 1
end tell # application "System Events"
tell me to beep 2
delay 0.5
tell application "System Events" to key code 18 using control down # return to Desktop 1
# ************************************
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
Robert Poland
Fort Collins CO
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden