Save Tabs using Script

Discuss and share scripts and script files...
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Save Tabs using Script

Post by SkyFrontier »

Considering this thread and this other,
zer0:
This should be possible using scripting, maybe even 2 panes in a sequence. Using <curpath> and #1018, one can whip up a script to cycle through tabs, saving their locations and then one can make a script to restore that group. Not easy, like Don said, but doable.
and
aurumdigitus:
After some head scratching cobbled together a simple script that changes among three TB's. Now really see your point. If the buttons were reset on return to the hopper that would almost defeat the whole purpose of CBT.
, also the limitations of catalog regarding saving tabs,

-can anyone please provide a script for saving sets of tabs (possibly inside an .ini file) and restoring then when requested?

This seems to be a frequent request over here and Don already said that "not for now", so we could have a place to point to.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Save Tabs using Script

Post by Stefan »

First try with one of several kind of coding this.


EDIT: see a few post below for an improved script.




Sessions.xys

Code: Select all

// save an list of current open Tabs from current pane to an file:
"Store Tabs"
   seltab 1;
   $TabOne = "<curpath>";

   $Tabs =;
  while (1){
    $Tabs = $Tabs . "<curpath>|";
    seltab +;
    IF ("<curpath>"=="$TabOne"){break;}
   }
  IF (exists("<xydata>\Sessions")==0) {new "<xydata>\Sessions", dir;}
  $SessionFile = Input("Title", "Save list of tabs as:", "<xydata>\Sessions\Sessions.ini");
  writefile($SessionFile, $Tabs, "o");


// open new tabs from an list of paths (saved tabs):
"Load Tabs"
   $SessionFile = inputfile("<xydata>\Sessions", "ini", "Load list of tabs");
   $Tabs = readfile($SessionFile);

  While(1){
    $OpenTab = regexreplace($Tabs, "(.+?)\|(.*)", "$1");
    $Tabs = regexreplace($Tabs, "(.+?)\|(.+)", "$2");
    #340; //open new tab
    GoTo $OpenTab;
    IF ($OpenTab|==$Tabs){break;}
   }
 
 
"Edit this &script : edit"
    self $ScriptFile, file;
    OpenWith "<xypath>\Tools\NotePad2\Notepad2.exe", ,$ScriptFile;
Disadvantage: if there are two tabs with same path, my script quits at the second found tab with that name.
@Don
the "seltab +;" do cycle from last tab to first and so on.
Could there be an option to stop at the most right tab? Like "seltab +!;"



ToDo:
* use save_as dialog ( savefile() like inputfile() )
Last edited by Stefan on 24 Jul 2010 22:52, edited 1 time in total.

admin
Site Admin
Posts: 60626
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Save Tabs using Script

Post by admin »

I think it would be a bit easier if I gave you a getInfo("tabs") and openInTabs(pathlist).

But note that each tab also might have fully defined find files specs and a search results cache... it's not just the path.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Save Tabs using Script

Post by Stefan »

admin wrote:I think it would be a bit easier if I gave you a getInfo("tabs") and openInTabs(pathlist).
Great. Do you mean:

seltab 1;
$TabCount = getInfo("tabs", count)

While ($TabCount > 0)
{...

$caption = getInfo("tabs", caption)
IF ($caption like "E:") {...;}

seltab +;
incr $TabCount, -1;
}

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Save Tabs using Script

Post by SkyFrontier »

Thanks, Stefan.
1st run told me the script can only save Pane 1 tabs.
Have to test it thoroughly, unable for the job right now - recovering another machine from crash.
Cya!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

admin
Site Admin
Posts: 60626
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Save Tabs using Script

Post by admin »

Stefan wrote:
admin wrote:I think it would be a bit easier if I gave you a getInfo("tabs") and openInTabs(pathlist).
Great. Do you mean:

seltab 1;
$TabCount = getInfo("tabs", count)

While ($TabCount > 0)
{...

$caption = getInfo("tabs", caption)
IF ($caption like "E:") {...;}

seltab +;
incr $TabCount, -1;
}
No, I meant

Code: Select all

$pathlistpane1 = getInfo("tabs", 1);
//store,... and later:
openInTabs $pathlistpane1;

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Save Tabs using Script

Post by Stefan »

O.K., but i hoped we could solve an another problem BTW:
How can i count open tabs (from one pane)?
Since 'seltab +;' does cycle from last to first.

I want to read the curpath of all tabs... but only once.
My solution above fails if two tabs point to the same path.
Did i have overseen an solution?

EDIT:
O.K. i could use
$count = getInfo("tabs", 1);
and then do an loop to count the tokens of $count

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Save Tabs using Script

Post by Stefan »

Thanks Don improvements in scripting i have update my "Store and Load Tabs as session"-script.


Sessions20100724.xys
Need latest XYplorer BETA version (v9.30.0012, 24-jul-2010) or any newer one.

Code: Select all

deleted

works only partly since i understood the syntax wrong

Sessions20100725.xys
Needs latest XYplorer BETA version (v9.30.0014, 25-jul-2010) or newer

Code: Select all

deleted

was too slow and stupid to change the tab to get the info. 

Sessions20100728.xys
Needs latest XYplorer BETA version (v9.30.0014, 25-jul-2010) or newer

Change log:
- No need to change tabs to get the info, just use tab(,,index) now.
+ add an sessions\sub-folder "ComputerName" for better handling of portable use
+ add an function to allow you to add an comment to your session file (in addition to modify the file name by an comment)
* change session file name to YYYMMDD HHNN_PaneX. You may modify $DefaultFileName to your needs if you prefer an other file name.

Code: Select all

//needs latest XYplorer BETA version (v9.30.0014, 25-jul-2010) or newer
//Note: depending on your XY settings something may not work as indented.

// save an list of current open Tabs from current pane to an file:
"Store Session/Tabs"
   $SubFolderName = "%computername%";  //"Work"; //sub-folder in sessions-folder
   $TabCount = tab(,"c"); //how many tabs are open?
   $Pane = getinfo("Pane"); //which pane is active?
   $Loop = 0;
   $Tabs = "";
 
   while ($Loop<$TabCount)  //for each tab do
   {
     //if (strlen(tab("get","name") < 1)
     $IFTabNameSet = strlen(tab("get","name",$Loop));
     if ($IFTabNameSet < 1)
     {
     $Tabs = $Tabs . tab("get", "data", $Loop) . "|"; //save the path in array "$Tabs" with | as delimiter
     }else{
     $Tabs = $Tabs . tab("get", "data", $Loop) . "?" . tab("get", "name", $Loop) . "|"; //save the tab caption too
     }
     incr $Loop;
    }
   
    //save the array to an file:
    //$folder = inputfolder("<xydata>\sessions", "Select Folder");
    IF (exists("<xydata>\Sessions\$SubFolderName")==0) {new "<xydata>\Sessions\$SubFolderName", dir;}

    $DefaultFileName = "<xydata>\Sessions\$SubFolderName\<date yyyymmdd hhnn>_Pane" . $Pane . ".ini";
    //
    $SessionFile = Input("Save Session", "Save list of tabs as: (you may add an description into the file name)", $DefaultFileName);
    //$SessionFile = $DefaultFileName;
    //

    writefile($SessionFile, $Tabs, "o");

    $Comment = Input("Session comment", "Enter an comment for this session (optional)",,"s","");
    comment $Comment, $SessionFile;



// ///////////////////////////////////////////////////////////////////////


// open new tabs from an list of paths (saved tabs):
"Load Session/Tabs"
    //read session file into array "$Tabs":
    $SubFolderName = "%computername%";  //"Work"; //sub-folder in sessions-folder
    $SessionFile = inputfile("<xydata>\Sessions\$SubFolderName", "ini", "Load list of tabs");
    $Tabs = readfile($SessionFile);
    $Loop = 1;
    
    //a little bit clean up first?
    $CloseCurrentOpenTabs = confirm("Close current open tabs first?");
    if ($CloseCurrentOpenTabs==0) { ;} elseif (tab(,"c")>1) {#353;} //close all "other" tabs


    $Loop = 1;
    While(1)
    {
      $NewTab = gettoken($Tabs,$Loop,"|");
      if ($NewTab==""){break;} 
      if (strpos($NewTab,"?") == -1)
      {
         tab("new", $NewTab); //open new tab with next token from array
      }else{ 
         tab("new",    gettoken($NewTab,1,"?"));
         tab("rename", gettoken($NewTab,2,"?"));
      }
    incr $Loop;
    }
    if ($CloseCurrentOpenTabs==1){seltab 1;#351;} //close last "old" tab too

-

"Edit this &script : edit"
    self $ScriptFile, file;
    //OpenWith "<xypath>\Tools\NotePad2\Notepad2.exe", ,$ScriptFile;
    OpenWith "Notepad", ,$ScriptFile;
    
Thank you Don!


Find me: save tab save tabs save session save sessions store tabs load tabs load session save project
Last edited by Stefan on 28 Jul 2010 09:55, edited 2 times in total.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Save Tabs using Script

Post by SkyFrontier »

One little report: for some unknown reason, it seems that the script is unable to restore pane 1/pane 2 tabs, switching then completely according to which pane was active on script launching. Is there a way to prevent that, Stefan...?
Many, many, many thanks!
-
Your File Selector script saved my skin: I moved 183 files to a folder containing 7023 items of the same kind, all of them with different creation dates. XYplorer's "undo" is not monitoring those changes on XP (seems ok on Win7), so when I realized the dumbness of my movement (5 days of bad sleeping can trash one...) it was too late. Luckily, I kept record of those files on a .txt, and Files Selector saved the day. Hoooray!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Save Tabs using Script

Post by Stefan »

SkyFrontier wrote:One little report:
for some unknown reason, it seems that the script is unable to restore pane 1/pane 2 tabs,
switching then completely according to which pane was active on script launching.
There is no relationship to an pane other than the "Pane n" -part in the session file name.
So you can load in pane 1 an session from pane 2.


BTW, i have updated my stupid script above. Hope the new version is now better (faster and no tab switching anymore)

Mr_Inc
Posts: 11
Joined: 27 Sep 2010 13:17

Re: Save Tabs using Script

Post by Mr_Inc »

If been playing around with this script to see if I could automate the swapping of panes and ALL their tabs. The "Swap Pane" function swaps tabs between panes and wasn't what I was after.

Anyway, I've had some success in doing this but I've noticed with the save portion of the script, the righmost tab is the first tab written to the file and as a result the tab loads in the wrong position.

In the script, instead of :-

$Loop = 0;
$Tabs = "";

while ($Loop<$TabCount) //for each tab do

Change it to:

$Loop = 1;
$Tabs = "";

while ($Loop<$TabCount+1) //for each tab do

Tabs seem to be loaded up in the same sequence when they were saved.

sam

Re: Save Tabs using Script

Post by sam »

sir,

Does the script works for the new versions of xy or do u need to update for every new
version ? finally check the script for bugs .

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Save Tabs using Script

Post by SkyFrontier »

Works Ok here.
EDIT: v9.60.0104.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Save Tabs using Script

Post by SkyFrontier »

Hmmmm... I see.
Trying to save sessions outside of <xydata> (quick test) results in error.
Sorry, can't provide a fix for now (quick look at the code/debug message gave me no clue, and I'm a script newbie, sorry for that...) but I'd advise you to save on suggested path as a workaround then move the file anywhere else - dual pane is a huge help on situations like this.
Perhaps original scripter is around and able to help us soon on this, Sam.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

sam

Re: Save Tabs using Script

Post by sam »

when i update to new version can tabs be restored?

Post Reply