Skip to content

Commit

Permalink
Improve Mac path discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
po5 committed Apr 29, 2023
1 parent ceb6ac4 commit 6cc936c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ It will be used in the background to generate thumbnails.
The only exception is [ImPlay](https://tsl0922.github.io/ImPlay/), which can do thumbnailing on its own.
Set `mpv_path=ImPlay` in `script-opts/thumbfast.conf` and make sure it's in [Path](https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14)#to-add-a-path-to-the-path-environment-variable).

## MacOS
If your mpv install is an app bundle (e.g. stolendata builds), the script will work but you may notice the Dock shakes when generating the first thumbnail.
To get rid of the shaking, make sure the app is in your Applications folder, then run: `sudo ln -s /Applications/mpv.app/Contents/MacOS/mpv /usr/local/mpv`
If you installed mpv via [Homebrew](https://brew.sh/), there are no issues.

## Configuration
`socket`: On Windows, a plain string. On Linux and Mac, a directory path for temporary files. Leave empty for auto.
`thumbnail`: Path for the temporary thumbnail file (must not be a directory). Leave empty for auto.
Expand Down
23 changes: 22 additions & 1 deletion thumbfast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,25 @@ end
local mpv_path = options.mpv_path

if mpv_path == "mpv" and os_name == "Mac" and unique then
-- TODO: look into ~~osxbundle/
mpv_path = string.gsub(subprocess({"ps", "-o", "comm=", "-p", tostring(unique)}).stdout, "[\n\r]", "")
mpv_path = string.gsub(mpv_path, "/mpv%-bundle$", "/mpv")
if mpv_path ~= "mpv" then
mpv_path = string.gsub(mpv_path, "/mpv%-bundle$", "/mpv")
local mpv_bin = mp.utils.file_info("/usr/local/mpv")
if mpv_bin and mpv_bin.is_file then
mpv_path = "/usr/local/mpv"
else
local mpv_app = mp.utils.file_info("/Applications/mpv.app/Contents/MacOS/mpv")
if mpv_app and mpv_app.is_file then
mp.msg.warn("symlink mpv to fix Dock icons: `sudo ln -s /Applications/mpv.app/Contents/MacOS/mpv /usr/local/mpv`")
--elseif string.match(mpv_path, "^/private/") then
-- mp.msg.warn("symlink mpv to fix Dock icons: `sudo ln -s 'PATH_TO_MPV_INSTALL_DIR/mpv.app/Contents/MacOS/mpv' /usr/local/mpv`")
else
-- mp.msg.warn("symlink mpv to fix Dock icons: `sudo ln -s '"..mpv_path.."' /usr/local/mpv`")
mp.msg.warn("drag to your Applications folder and symlink mpv to fix Dock icons: `sudo ln -s /Applications/mpv.app/Contents/MacOS/mpv /usr/local/mpv`")
end
end
end
end

local function vf_string(filters, full)
Expand Down Expand Up @@ -371,6 +388,10 @@ local function spawn(time)
table.insert(args, "--sws-allow-zimg=no")
end

if os_name == "Mac" and mp.get_property("macos-app-activation-policy") then
table.insert(args, "--macos-app-activation-policy=accessory")
end

if os_name == "Windows" then
table.insert(args, "--input-ipc-server="..options.socket)
else
Expand Down

5 comments on commit 6cc936c

@hooke007
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundle app could be run anywhere, hardcoded with a fixed directory is not perfect.

@po5
Copy link
Owner Author

@po5 po5 commented on 6cc936c Apr 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left the code for the dynamic command in a comment, not being a Mac user I wasn't sure if it's advisable to symlink to a file that can change location at any time.
Telling the user to install it as a normal application seems like a good solution, then it doesn't risk moving around.
We do tell the user to drag it to the Applications folder when the bundle is run from a random place.

Would you rather have the code that's currently commented out? Or did I go wrong there too :^)

@hooke007
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I do not have a better solution. I prefer to adding the info in README to tell Mac users.

@po5
Copy link
Owner Author

@po5 po5 commented on 6cc936c Apr 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hooke007
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i see.

Please sign in to comment.