help to pass $INFO[ListItem.Path] to a script
#1
Hello to all!

I need some help to get something to work, if possible:

I have this button on skin to run a script:
Code:

<control type="button" id="1032">
     <include>DialogSettingButton</include>
     <onclick>RunScript(special://skin/extras/script/make_album.py</onclick>
     <label>Albuns</label>
     <align>center</align>
</control>

This button is executaded by a context menu on PICTURES Window:
Image

As you can see, right above the image of the man with a hat, there a path: "D:\Wallpapers\Music Genre\". This path is the $INFO[ListItem.Path].

This is the script:
Code:
import xbmc
import xbmcgui

local = "I need to put $INFO[ListItem.Path] here" 

with open(local + 'readme.album', 'w') as f:
    f.write('this is a album file!')
xbmcgui.Dialog().notification('Kodi', 'Album Created', xbmcgui.NOTIFICATION_WARNING, 5)

Is there a way to set the local variable as "$INFO[ListItem.Path]" ?

OBS: The script work if I set "local" to a fixed local, like: local = 'D:\Wallpapers\Music Genre\'. But, I want to be dinamic with the path on kodi.

Thanks in Advance!
Reply
#2
RunScript can pass information into a script using this format:

xml:

RunScript(special://skin/extras/script/make_album.py,extra info here)

So maybe:

xml:

<control type="button" id="1032">
     <include>DialogSettingButton</include>
     <onclick>RunScript(special://skin/extras/script/make_album.py,$INFO[ListItem.Path])</onclick>
     <label>Albuns</label>
     <align>center</align>
</control>

It's worth noting that you were missing the close parenthesis at the end of the RunScript call in your original example.

Assuming that works (I'm not a context menu or skin expert), you can get the value passed from sys.argv[1].  So the script becomes:

python:

import xbmc
import xbmcgui
import sys

local = sys.argv[1]

with open(local + 'readme.album', 'w') as f:
    f.write('this is a album file!')
xbmcgui.Dialog().notification('Kodi', 'Album Created', xbmcgui.NOTIFICATION_WARNING, 5)
Reply
#3
THIS!!!!!!

So simple and so powerfull!!!!

Very thanks!!!!!!

With this I can make more variables? 
like 
Code:
<onclick>RunScript(special://skin/extras/script/make_album.py, $INFO[ListItem.Path], var2, var3)</onclick>

and

Code:
newvar2 = sys.argv[2]
newvar3 = sys.argv[3]

this way?
Reply
#4
(2022-08-07, 18:50)sagrath Wrote: With this I can make more variables? 
like 
 
Code:
<onclick>RunScript(special://skin/extras/script/make_album.py, $INFO[ListItem.Path], var2, var3)</onclick>
and
 
Code:
newvar2 = sys.argv[2]
newvar3 = sys.argv[3]

I checked the documentation, and it does look like you can do additional variables just like you showed.  I've never tried it, so all I can say is that it should work.
Reply
#5
in addition, you can also pass arguemts via addon xml since Matrix version via addon.xml

Kodi v19 Matrix and later.
In Kodi v19 Matrix and later, it is possible to specify an optional args attribute to a context item. The contents of this attribute will be passed as an argument to the script specified in the library attribute. It can be accessed via sys.argv. The combination of args and library need to be unique. Duplicate combinations are ignored.
https://kodi.wiki/view/Context_Item_Add-ons

e.g.
xml:
 
<item library="contextmenu.py" args="execute,method=open_playercontrol">
    <label>$LOCALIZE[10114]</label>
    <visible>!Window.IsActive(playercontrols) + [Player.HasMedia + [MusicPlayer.Offset(-1).Exists | MusicPlayer.Offset(1).Exists]]</visible>
</item>
Skins |  Titan M O D   •   S W A N (WIP)
Reply

Logout Mark Read Team Forum Stats Members Help
help to pass $INFO[ListItem.Path] to a script0