Use already-open QuickTime windows, instead of taking a file list to open
This commit is contained in:
parent
d6ee17292b
commit
fb46b59591
88
mosaic.lua
88
mosaic.lua
|
|
@ -1,8 +1,8 @@
|
||||||
-- 1. CONFIGURATION
|
-- 1. CONFIGURATION
|
||||||
|
|
||||||
screen_width = 1000 -- FIXME
|
screen_width = 1080 -- FIXME
|
||||||
aspect_ratio = 1.5 -- a good default for dragonframe's typical 1620x1080 exports
|
aspect_ratio = 1.5 -- a good default for dragonframe's typical 1620x1080 exports
|
||||||
window_titlebar_height = 39
|
menubar_height = 39
|
||||||
|
|
||||||
|
|
||||||
-- 2. UTILITY FUNCTIONS
|
-- 2. UTILITY FUNCTIONS
|
||||||
|
|
@ -23,74 +23,70 @@ function linesToTable(s)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 3. COUNT WINDOWS + SET UP GRID
|
||||||
|
|
||||||
-- 3. GET FILE LIST
|
number_of_windows = tonumber(exec("osascript -e 'tell application \"System Events\" to count (windows of process \"QuickTime Player\" where value of attribute \"AXMinimized\" is false)'"))
|
||||||
-- TODO: get these some other way that's easier to use...
|
print("There are currently "..number_of_windows.." non-minimized QuickTime windows")
|
||||||
-- maybe args passed in from an Automater script?
|
|
||||||
|
|
||||||
local cd = exec("pwd")
|
|
||||||
local files = exec('stat -f "%N" *.mp4')
|
|
||||||
|
|
||||||
-- Create a table containing the complete path to every video:
|
|
||||||
local filetable = linesToTable(files)
|
|
||||||
for k, file in ipairs(filetable) do
|
|
||||||
print("k "..k.." v "..file)
|
|
||||||
filetable[k] = cd.."/"..file
|
|
||||||
print(filetable[k])
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- 4. PREP FOR PLAYING
|
|
||||||
|
|
||||||
-- FIXME:
|
-- FIXME:
|
||||||
if #filetable <= 9 then
|
if number_of_windows <= 9 then
|
||||||
cols = 3
|
cols = 3
|
||||||
rows = 3
|
rows = 3
|
||||||
|
elseif number_of_windows <= 12 then
|
||||||
|
cols = 3
|
||||||
|
rows = 4
|
||||||
|
elseif number_of_windows <= 16 then
|
||||||
|
cols = 4
|
||||||
|
rows = 4
|
||||||
|
elseif number_of_windows <= 20 then
|
||||||
|
cols = 4
|
||||||
|
rows = 5
|
||||||
|
elseif number_of_windows <= 25 then
|
||||||
|
cols = 5
|
||||||
|
rows = 5
|
||||||
|
elseif number_of_windows <= 30 then
|
||||||
|
cols = 5
|
||||||
|
rows = 6
|
||||||
|
elseif number_of_windows <= 36 then
|
||||||
|
cols = 6
|
||||||
|
rows = 6
|
||||||
|
else
|
||||||
|
os.execute("osascript -e 'display dialog \"you have too many videos lol\"'")
|
||||||
|
os.exit()
|
||||||
end
|
end
|
||||||
|
|
||||||
video_width = screen_width // cols -- "floor division" returns an integer
|
video_width = screen_width // cols -- "floor division" returns an integer
|
||||||
video_height = video_width // aspect_ratio
|
video_height = video_width // aspect_ratio
|
||||||
|
|
||||||
|
|
||||||
-- 5. PLAY + POSITION VIDEOS
|
-- 4. PLAY + POSITION VIDEOS
|
||||||
|
|
||||||
-- We're going to loop through the list of videos.
|
-- For each QuickTime window we will:
|
||||||
-- For each video we will:
|
-- 1. use AppleScript to play it on loop
|
||||||
-- 1. use AppleScript to open it, playing on loop
|
|
||||||
-- 2. move it to the appropriate position
|
-- 2. move it to the appropriate position
|
||||||
|
|
||||||
current_col = 1
|
current_col = 1
|
||||||
current_row = 1
|
current_row = 1
|
||||||
for _, file in ipairs(filetable) do
|
for i = 1, number_of_windows do
|
||||||
print("opening "..file)
|
|
||||||
print(string.format(" col: %s, row: %s", current_col, current_row))
|
|
||||||
|
|
||||||
-- Calculate position / dimensions
|
-- Calculate position / dimensions
|
||||||
local x1 = (current_col * video_width) - video_width
|
local x1 = (current_col * video_width) - video_width
|
||||||
local y1 = (current_row * video_height) - video_height + (current_row * window_titlebar_height) - window_titlebar_height
|
local y1 = (current_row * video_height) - video_height + menubar_height
|
||||||
local x2 = x1 + video_width
|
local x2 = x1 + video_width
|
||||||
local y2 = y1 + video_height
|
local y2 = y1 + video_height
|
||||||
local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2)
|
local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2)
|
||||||
|
print(string.format("row %s, col %s: %s", current_row, current_col, bounds))
|
||||||
|
|
||||||
print(" "..bounds)
|
-- Loop
|
||||||
print()
|
local loopCmd = string.format('tell application "QuickTime Player" to set the looping of document %d to true', i)
|
||||||
|
os.execute("osascript -e '"..loopCmd.."'")
|
||||||
|
|
||||||
-- Open the video + play it on loop
|
-- Play
|
||||||
os.execute(
|
local playCmd = string.format('tell application "QuickTime Player" to play document %d', i)
|
||||||
string.format(
|
os.execute("osascript -e '"..playCmd.."'")
|
||||||
[[osascript -e '
|
|
||||||
set f to POSIX file "%s"
|
|
||||||
tell application "QuickTime Player"
|
|
||||||
set theMovie to open file f
|
|
||||||
tell theMovie
|
|
||||||
set the looping of theMovie to true
|
|
||||||
play
|
|
||||||
end tell
|
|
||||||
end tell'
|
|
||||||
]], file))
|
|
||||||
|
|
||||||
-- Move it to the correct spot on the screen
|
-- Move
|
||||||
os.execute(string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds))
|
local moveCmd = string.format('tell application "QuickTime Player" to set the bounds of window %d to %s', i, bounds)
|
||||||
|
os.execute("osascript -e '"..moveCmd.."'")
|
||||||
|
|
||||||
-- Update grid positioning for the next iteration
|
-- Update grid positioning for the next iteration
|
||||||
current_col = current_col + 1
|
current_col = current_col + 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue