when this function is called and some files are chosen in the dialog, the file paths should be printed to the console, but it actually print nothing:
function printAllChosenFiles()
local t = hs.dialog.chooseFileOrFolder("", "", true, false, true)
for i = 1, #t do
print(t[i])
end
end
I checked the source code, it's because of this line:
https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/dialog/libdialog.m#L426
lua_pushstring(L,[[url path] UTF8String]); lua_setfield(L, -2, [[NSString stringWithFormat:@"%i", count] UTF8String]);
here it set the file paths as values with string keys like "1", "2", "3" instead of integer keys 1, 2, 3.
as the document of this function says it returns "The selected files in a table or nil if cancel was pressed.", I think comparing to a table with string "1", "2", "3" keys, an array-like table is more close to the document, users are more likely to expect an array-like table, and an array-like table is more convenient for users (like iterating it).
obviously the fixing is easy, just replace lua_setfield(L, -2, [[NSString stringWithFormat:@"%i", count] UTF8String]); with lua_seti(L, -2, count);
when this function is called and some files are chosen in the dialog, the file paths should be printed to the console, but it actually print nothing:
I checked the source code, it's because of this line:
https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/dialog/libdialog.m#L426
lua_pushstring(L,[[url path] UTF8String]); lua_setfield(L, -2, [[NSString stringWithFormat:@"%i", count] UTF8String]);here it set the file paths as values with string keys like "1", "2", "3" instead of integer keys 1, 2, 3.
as the document of this function says it returns "The selected files in a table or nil if cancel was pressed.", I think comparing to a table with string "1", "2", "3" keys, an array-like table is more close to the document, users are more likely to expect an array-like table, and an array-like table is more convenient for users (like iterating it).
obviously the fixing is easy, just replace
lua_setfield(L, -2, [[NSString stringWithFormat:@"%i", count] UTF8String]);withlua_seti(L, -2, count);