Replies: 1 comment 1 reply
-
I assume you want the directory of the file instead of the path: local utils = require 'mp.utils'
mp.register_event('file-loaded', function()
local directory, _ = utils.split_path(utils.join_path(mp.get_property('working-directory'), mp.get_property('path')))
print(directory)
end) On master: local utils = require 'mp.utils'
mp.register_event('file-loaded', function()
local directory, _ = utils.split_path(mp.command_native({'normalize-path', mp.get_property('path')}))
print(directory)
end) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been looking for a way for actual hours, i've seen other scripts do it but when I try to replicate it their way it always fails...
local path = utils.getcwd()
is the best i've got but it only works when opened from a terminal because the file manager (for some reason) sets the launch path to my home directory, no matter which directory i'm actually in.I tried various things. Furthest I gat was this.
which returns a '.' for dir and nothing at all for filename, doesn't actually give me a proper path. Most other things i tried just return 'nil'. I've seen this used in a bunch of other scripts and it seems to work there, but not in mine for no discernible reason (i'm literally running this at the start of the script)
For instance:
Gives me
Lua error: /home/rabcor/.config/mpv/scripts/script.lua:33: bad argument #1 to 'split_path' (string expected, got nil)
local test = mp.get_property_native('playlist')[1].filename
gives me filename but no path...How do i get the real path of the current file? or just filename with path?
Beta Was this translation helpful? Give feedback.
All reactions