Create macOS application bundle

This commit is contained in:
n loewen 2024-05-06 17:12:49 -07:00
parent 91ee4fc36e
commit 2df4414baa
1 changed files with 99 additions and 0 deletions

99
vidgrid.app/vidgrid Executable file
View File

@ -0,0 +1,99 @@
#!/usr/bin/env lua
-- 1. CONFIGURATION
screen_width = 1080 -- FIXME
aspect_ratio = 1.5 -- a good default for dragonframe's typical 1620x1080 exports
menubar_height = 39
-- 2. UTILITY FUNCTIONS
function exec(cmd)
local handle = io.popen(cmd)
local result = handle:read("*a")
handle:close()
result = result:sub(1, #result - 1) -- remove trailing newline
return result
end
function linesToTable(s)
local t = {}
for x in string.gmatch(s, "([^%s]+)") do
table.insert(t, x)
end
return t
end
-- 3. COUNT WINDOWS + SET UP GRID
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)'"))
print("There are currently "..number_of_windows.." non-minimized QuickTime windows")
-- FIXME:
if number_of_windows <= 9 then
cols = 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
video_width = screen_width // cols -- "floor division" returns an integer
video_height = video_width // aspect_ratio
-- 4. PLAY + POSITION VIDEOS
-- For each QuickTime window we will:
-- 1. use AppleScript to play it on loop
-- 2. move it to the appropriate position
current_col = 1
current_row = 1
for i = 1, number_of_windows do
-- Calculate position / dimensions
local x1 = (current_col * video_width) - video_width
local y1 = (current_row * video_height) - video_height + menubar_height
local x2 = x1 + video_width
local y2 = y1 + video_height
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))
-- Loop
local loopCmd = string.format('tell application "QuickTime Player" to set the looping of document %d to true', i)
os.execute("osascript -e '"..loopCmd.."'")
-- Play
local playCmd = string.format('tell application "QuickTime Player" to play document %d', i)
os.execute("osascript -e '"..playCmd.."'")
-- Move
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
current_col = current_col + 1
if current_col > cols then
current_col = 1
current_row = current_row + 1
end
end