Guest User

A Python.js

a guest
Jun 7th, 2026
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. function GetContext()
  2. {
  3. var ctx = {
  4. source: Salamander.SourcePanel.Path,
  5. target: Salamander.TargetPanel.Path,
  6. files: []
  7. };
  8.  
  9. var items = null;
  10.  
  11. if (Salamander.SourcePanel.SelectedItems.Count > 0)
  12. {
  13. items = Salamander.SourcePanel.SelectedItems;
  14. }
  15. else if (Salamander.SourcePanel.FocusedItem &&
  16. Salamander.SourcePanel.FocusedItem.Name != "..")
  17. {
  18. items = new Array();
  19. items[0] = Salamander.SourcePanel.FocusedItem;
  20. }
  21.  
  22. if (items == null)
  23. return ctx;
  24.  
  25. for (var e = new Enumerator(items); !e.atEnd(); e.moveNext())
  26. {
  27. var item = e.item();
  28.  
  29. if (!(item.Attributes & 16))
  30. {
  31. ctx.files.push(
  32. Salamander.SourcePanel.Path + "\\" + item.Name
  33. );
  34. }
  35. }
  36.  
  37. return ctx;
  38. }
  39.  
  40. function SerializeContext(ctx)
  41. {
  42. var s = "";
  43.  
  44. s += "SRC=" + ctx.source + "\n";
  45. s += "DEST=" + ctx.target + "\n";
  46.  
  47. for (var i = 0; i < ctx.files.length; i++)
  48. {
  49. s += "FILE=" + ctx.files[i] + "\n";
  50. }
  51.  
  52. return s;
  53. }
  54.  
  55. function Main()
  56. {
  57. var ctx = GetContext();
  58.  
  59. if (ctx.files.length == 0)
  60. {
  61. Salamander.MsgBox("Nie sú vybrané žiadne súbory.");
  62. return;
  63. }
  64.  
  65. var json = SerializeContext(ctx);
  66.  
  67. var shell = new ActiveXObject("WScript.Shell");
  68.  
  69. var exec = shell.Exec(
  70. 'python "C:\\Users\\Admin\\Documents\\PythonAPI.py"'
  71. );
  72.  
  73. exec.StdIn.Write(json);
  74. exec.StdIn.Close();
  75.  
  76. while (exec.Status == 0)
  77. {
  78. Salamander.Sleep(50);
  79. }
  80.  
  81. var result = exec.StdOut.ReadAll();
  82.  
  83. result = result.replace(/^\s+|\s+$/g, "");
  84.  
  85. if (result.indexOf("TARGET|") == 0)
  86. {
  87. Salamander.TargetPanel.Path =
  88. result.substr(7);
  89. }
  90. else
  91. {
  92. Salamander.MsgBox(result, 32, "Python");
  93. }
  94. }
  95.  
  96. Main();
Advertisement
Add Comment
Please, Sign In to add comment