Reposition/Resize QuickLook window with AppleScript

applescriptquicklook

Is there a way to resize and reposition a quick look window with AppleScript? I have an AppleScript that will do this with any app, but I do not know what the quick look app is called.

I have tried QuickLook, Quick Look, and QL.

Best Answer

Here's a little AppleScript I wrote to resize and reposition the Quick Look window so that it occupies the right one-third of the screen:

    tell application "System Events"
        if not (exists window "Quick Look") of process "Finder" then
            activate application "Finder"
            keystroke "y" using command down
        end if
    end tell

    tell application "System Events" to tell process "Finder"
        if not (exists window "Quick Look") then ¬
            with timeout of 5 seconds
                repeat until (exists window "Quick Look")
                end repeat
            end timeout

        set [W, H] to size of scroll area 1 --(desktop)

        tell window "Quick Look"
            set [_w, _h] to size
            set [_x, _y] to position

            set position of it to [W * 2 / 3, 0]
            set size of it to [W * 1 / 3, H]
        end tell
    end tell

This requires that the appropriate application from within which this script is run (e.g. Script Editor, Keyboard Maestro, Better Touch Tool, etc.) is given assistive accessibility permissions, which (in High Sierra) you can grant in System Preferences > Security & Privacy > Privacy > Accessibility.