1

I want to write an AppleScript App that starts a full screen slideshow with all pictures in the currently active folder in Finder (on Big Sur/Apple M1).

Manually, in Finder I would have to open a folder, press command ⌘+ A to select all pictures (or files) inside, then press option ⌥+ spacebar to start the slideshow.

I want to write a Script-App, that does all that for me (and which I then can put in Finder's toolbar). I am a newbie to this all, so please explain it for the dummy I am!

1
  • What have you tried so far?
    – nohillside
    Commented Feb 15, 2021 at 16:46

2 Answers 2

0

I figured it out and wrote a simple script, that does this: 1) opens the selected folder in Finder 2) selects all files in that folder 3) starts slideshow. Can be saved as an App and then put in the toolbar of Finder. Works on Big Sur/M1, however you have to allow Script Editor and this App 'Accessibility' and 'Automation' in System Preferences/Security&Privacy.

Any improvements are highly welcome! Especially I couldn't figure out how to make the Script close the selected/opened Folder again and go one level up again. Key code for that would be "key code 126 using {command down}" (for COMMAND+ARROW UP); however, don't know how to integrate that into the script so that it actually works.

tell application "Finder"
    activate
    tell application "System Events"
        tell process "Finder"
            key code 31 using {command down}
        end tell
    end tell
    
    activate
    tell application "System Events"
        tell process "Finder"
            key code 0 using {command down}
        end tell
    end tell
    
    activate
    tell application "System Events"
        tell process "Finder"
            key code 49 using {option down}
        end tell
    end tell
end tell
0

I do not have an M1 Mac, however, the following was tested and works on an Intel based Mac running macOS Big Sur.

The intent of the example AppleScript code, shown below, is to mimic the manual events necessary to start a slideshow of the selected items in Finder, or the contents of the window itself with nothing selected, by doing it with an AppleScript application placed in its Toolbar.

  • If nothing is selected in the front window when the app icon is clicked in the Toolbar, then all items are selected and the slideshow starts.

  • If individual files are selected in the front window when the app icon is clicked in the Toolbar, the slideshow starts with the selected individual files.

  • If a folder is selected in the front window when the app icon is clicked in the Toolbar, then if the folder is not already opened, its opened, the items are selected and the slideshow starts. If the folder is already opened, the items are selected and the slideshow starts. This takes into account the various views the window can be in, i.e., icon view, list view, or column view.

Note that no other manipulation of the state of the front window is attempted after the slideshow finishes because, if it was started manually, any other actions would have to be done so manually after the fact anyway. Additionally, any AppleScript method employed, if possible, to trigger something after the slideshow finishes would probably be resource intensive, having to constantly monitor its state and act accordingly. Therefore I do not consider it practical to implement, even if it's possible to do.

The example AppleScript code was saved as an AppleScript application named Start Slideshow in Script Editor, given a custom icon in Finder and added to its Toolbar, as shown in the image below.

enter image description here


Example AppleScript code:

tell application "Finder"
    activate
    set mySelection to selection
    if mySelection is {} then
        set selection to every item of front window
        my startSlideshow()
    else
        set mySelectionAlias to first item of mySelection as alias
        set mySelectionAliasProperties to properties of mySelectionAlias
        if the class of mySelectionAliasProperties is folder then
            if name of front window is equal to name of mySelectionAliasProperties then
                set selection to every item of front window
                my startSlideshow()
            else
                my openFolder()
                set selection to every item of front window
                my startSlideshow()
            end if
        else
            my startSlideshow()
        end if
    end if
end tell

on openFolder()
    tell application "System Events" to ¬
        key code 31 using command down
    delay 0.2
end openFolder

on startSlideshow()
    tell application "System Events" to ¬
        key code 49 using option down
end startSlideshow

Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

2
  • @UVy, I've updated my answer with different code. Commented Feb 16, 2021 at 15:17
  • I tested it ob M1/Big Sur, works fine! Thank you!
    – user406773
    Commented Feb 25, 2021 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .