• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: set picture of current desktop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set picture of current desktop


  • Subject: Re: set picture of current desktop
  • From: Robert Poland <email@hidden>
  • Date: Mon, 11 Jun 2018 09:41:31 -0600
  • Z-usanet-msgid: XID565wFkPph5376X32

Yvan,

Rather than trying ti disect your script, here’s what I have been doing;

(* Set_Spaces - 11/25/13 - By R Poland    1/5/14 - Added nullPicture
11/12/14 - set default Choose folder, Help from Yvan
*)

tell application "System Events" to key code 18 using control down # Move to
desktop 1
set volume output volume 50
set TicTock to 0.4
tell application "Finder" to select {} -- deselect selection(s)

# pick a new background image
set nullPicture to "~/Pictures/APOD ƒ/nullPicture.jpg" # Temp blank image
# use a function from the OSAX Standard Additions
set theFolder to (path to home folder as text) & "Pictures:APOD ƒ:"
set ThePicture to (choose file default location alias theFolder)
tell application "System Events" to set ThePicture2 to (name of ThePicture)
set ThePicture2 to "/Users/rpoland/Pictures/APOD ƒ/" & ThePicture2
delay TicTock
tell application "System Events" to set the_size to size of ThePicture
tell application "System Events" to set modDate to modification date of
ThePicture as string
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 erro -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
        quit # exit to release "Wrong?" window
end tell
delay TicTock # 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
        set switchTo_loc to my recolle(items 1 thru -2 of my
decoupe(switchTo_loc, space), space)
end if

## set volume output volume 100

tell application "System Preferences"
        # set quit (delay) to 0
        activate
        # set Peferences to show all.
        tell application "System Events" to keystroke "L" using (command down)
        delay TicTock
        reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
end tell # application "System Preferences"
delay TicTock
tell application "System Events"
        activate
        delay 0.5 # some cases need extra time
        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 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
                delay TicTock
        end tell # process "System Preferences"


        delay TicTock
        tell application "System Preferences" to quit
        delay TicTock
        key code 18 using control down # Move to desktop 1
        delay TicTock
        # ************************************
        #
        # ************************************
        # 18 = space 1
        set actualSpaces to 18 + numSpaces
        repeat with i from 18 to (actualSpaces + 1)
                delay TicTock
                -- tell application "System Events"
                try -- don't error if old picture is gone.
                        set backGroundPath to (picture of current desktop)
                        set backGroundDate to modification date of file
backGroundPath as string
                on error
                        set backGroundDate to ""
                end try
                delay 2
                ## display dialog "backGroundDate " & return & return &
backGroundDate & return & return & "modDatemodDate " & return & return & "
backGroundPath " & return & return & backGroundPath & return & return & return
& "backGroundPath " & return & return & backGroundPath & return & return &
"ThePicture2 " & return & return & ThePicture2

                if backGroundDate ≠ modDate or backGroundPath ≠ ThePicture2 then
                        tell current desktop
                                set picture to nullPicture # wipe out current
Picture
                                delay TicTock * 2
                                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 (TicTock * 2)
                        end tell
                end if -- if backGroundName ≠ thepicture
                # switch to the next desktop
                delay 1

                if i = 18 then
                        -- key code 18 using control down # 1
                else if i = 19 then
                        key code 19 using control down # 2
                else if i = 20 then
                        key code 20 using control down # 3
                else if i = 21 then
                        key code 21 using control down # 4
                else if i = 22 then
                        key code 23 using control down # 5
                else if i = 23 then
                        key code 22 using control down # 6
                else
                        key code 26 using control down # 7
                end if

                delay 1
        end repeat # 1 to numSpaces
        # ************************************
        #
        # ************************************
        delay TicTock
end tell # application "System Events"
tell me to beep 2
delay 1
tell application "System Events" to key code 18 using control down # return to
Desktop 1
delay 0.2
tell application "System Events" to key code 18 using control down # return to
Desktop 1
## set volume output volume 50
# ************************************

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

on delay delayTime
        (* try
                set theRepeat to delayTime * 10 div 1
                repeat theRepeat times *)
        do shell script "sleep 0.1"
        (* end repeat
        on error
                repeat 10 times # default time - 1 second
                        do shell script "sleep 0.1"
                end repeat
        end try *)
end delay






> On Jun 11, 2018, at 9:36 AM, Yvan KOENIG <email@hidden> wrote:
>
> Hello
>
> Is one of you able to tell me what is wrong with this code which is supposed
> to set the picture of the current desktop ?
> It defines the desktop's properties but fails to display the picture.
>
> set theFile to choose file of type {"jpeg", "jpg"}
>
> tell application "System Events"
>       set pictFolder to path of container of theFile
> end tell
>
> set PosixFolder to POSIX path of pictFolder
> set PosixFile to POSIX path of theFile
>
> tell application "System Events"
>       tell current desktop
>               set pictures folder to PosixFolder
>               set picture to PosixFile
>               get properties
>               --> {display name:"iMac", change interval:1800.0, id:69731072,
> random order:false, picture rotation:0, pictures
> folder:"/Users/**********/Desktop/",
> picture:"/Users/**********/Desktop/20170614_154507_p-2017-amenagement-interieur-jean-marc-renou2.jpg",
>  translucent menu bar:missing value, class:desktop}
>       end tell
> end tell
>
> Yvan KOENIG running High Sierra 10.13.5 in French (VALLAURIS, France) lundi
> 11 juin 2018 17:36:21
>
>
>
> _______________________________________________
> 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

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

  • Follow-Ups:
    • Re: set picture of current desktop
      • From: Yvan KOENIG <email@hidden>
References: 
 >set picture of current desktop (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: set picture of current desktop
  • Next by Date: Re: set picture of current desktop
  • Previous by thread: set picture of current desktop
  • Next by thread: Re: set picture of current desktop
  • Index(es):
    • Date
    • Thread