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 local cd = exec("pwd") -- print("| "..cd.." |") local files = exec('stat -f "%N" *.mp4') -- print("| "..files.." |") local filetable = linesToTable(files) for k, file in ipairs(filetable) do print("k "..k.." v "..file) filetable[k] = cd.."/"..file print(filetable[k]) end -- FIXME: if #filetable <= 9 then cols = 3 rows = 3 end -- FIXME: screen_width = 1000 aspect_ratio = 1.5 video_width = screen_width // cols -- "floor division" returns an integer video_height = video_width // aspect_ratio window_titlebar_height = 39 current_col = 1 current_row = 1 for _, file in ipairs(filetable) do print("opening "..file) print(string.format(" col: %s, row: %s", current_col, current_row)) 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 x2 = x1 + video_width local y2 = y1 + video_height local bounds = string.format("{%d, %d, %d, %d}", x1, y1, x2, y2) print(" "..bounds) print() -- os.execute(string.format("open -a 'QuickTime Player' %s", file)) os.execute( string.format( [[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)) local cmd = string.format("osascript -e 'tell application \"%s\" to set the bounds of the front window to %s'", "QuickTime Player", bounds) print(cmd) os.execute(cmd) current_col = current_col + 1 if current_col > cols then current_col = 1 current_row = current_row + 1 end end