Check if paperfolder active

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Stef123

Check if paperfolder active

Post by Stef123 »

What I'd like to do in a script:
Check if active pane shows a paperfolder
If so, then return its full name.

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

Re: Check if paperfolder active

Post by SkyFrontier »

List tabs, check paper folder, compare its base name with <xypaper> contents...?
(can't test the theory as of now, just an idea)
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...

Stef123

Re: Check if paperfolder active

Post by Stef123 »

Thanks Sky,
I was hoping for an easy way, some built-in detection SC command not known to me. But if nothing else turns up, I'd appreciate your help in the direction you pointed to. Not sure I understand what you mean by comparing the base name with <xypaper> contents. Pleaes explain whenever you find time.

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

Re: Check if paperfolder active

Post by SkyFrontier »

Ok. A bit busy as of now, but may come up with something asap. Just a concept, as said, but sounds promising to me. Will test the limits (for instance, 2 paper folders listed) and check docs for a proper solution.
Stay tuned.
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...

Stef123

Re: Check if paperfolder active

Post by Stef123 »

Take your time. Just to make sure there is no misunderstanding - I need SC to recognize whether or not the active pane is in "paperfolder view mode" so to speak. I am not interested in its contents at this point, neither PF content nor regular list view content. Only want to see if a paperfolder is ON, and what PF file it is. SC-wise, without peeking at the blue title tab.

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

Re: Check if paperfolder active

Post by SkyFrontier »

what about this:

echo tab("get", "path");

-does this suffice to you or do you need anything else?

(expanding, in case you already haven't seeing this:)
the code returns "paper:test", from an active tab displaying a paper folder.

A full test, then, would be:

Code: Select all

  $tst = tab("get", "path");
  $tst2 = gettoken("$tst", 1, ":");
  if($tst2 == "paper") {
     $nm = gettoken("$tst", 2, ":");
                      echo "I'm a paper, boy, and my name's '$nm'.";
                       }
   else { echo "Let the river flow: I'm not a paper!"; }
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...

Stef123

Re: Check if paperfolder active

Post by Stef123 »

Wow, thanks, :tup:
Although it still beats me how you pull this off. Not coming to terms with this gettoken stuff, but anyhow - tried modifing the parameters to get the full path, but I am just not up to par with these things.

Could you tweak it to show me the full path? I need to treat this file to a recoding makeover (related to my other post, UTF-8) - to automate the tedious manual conversions, but for that I need the file itself, not just the name-part.

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

Re: Check if paperfolder active

Post by SkyFrontier »

sure.

Code: Select all

  $tst = tab("get", "path");
  $tst2 = gettoken("$tst", 1, ":");
  if($tst2 == "paper") {
     $nm = gettoken("$tst", 2, ":");
//assuming that current rules will still apply: 
//*all* papers are hold under <xypaper>, have ".txt" as ext
   $pth = "<xypaper>" . "\" . "$nm" . ".txt";
                      echo "I'm a paper, boy, and my path's:<crlf>'$pth'.";
                       }
   else { echo "Let the river flow: I'm not a paper!"; }
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...

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Check if paperfolder active

Post by bdeshi »

But paperfolder files can exist outside of <xypaper>.

Code: Select all

  $tab = tab('get', 'path');                                    // the tab location.
  end (gettoken($tab, 1, ':') != 'paper'),'Not a PaperFolder';  // if no paper: prefix, it's not a PF.
  $main = gettoken($tab, 2, ':',, 2).'.txt';                    // get the base/main paperpath element from tabpath.
                                                                // paperfiles have txt extension,but hidden in GUI.
  if exists($main){ $path = $main; }                            // if the path exists by itself, its a full path to
                                                                // an <xypaper> - external paper file.
  else            { $path = resolvepath($main, "<xypaper>\"); } // else make absolute path to paperfile in <xypaper>
  echo $path;                                                   // echo the absolutified path to paper file
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: Check if paperfolder active

Post by Stef123 »

Whoa - that's the intimidating thing with scripting, it always turns out much more complicated. I would have been on the wrong track completely, assuming it's just another tweak on the gettoken parameters.

So anyway, unfortunately it still does not give me the path name. What I get is really weird, it gives me a totally unrelated path and the file name is just a single letter with the extension txt.

Judging from the code, you're kind of manufacturing it, in a Frankenstein-ian way of operating, grafting limbs and extensions on top of it. Which doesn't bother me, if the result would equal the real thing. Is there any way to let it read out the real path?

Just seeing Sammay's post right now - thanks for chiming in - will try it out later, got stuff coming up.....

Stef123

Re: Check if paperfolder active

Post by Stef123 »

Thank you - this works exactly like I had hoped for. :beer:
Trying to learn something here - so you both started out the same way by analyzing the tab caption and taking it apart into components before and after colons :

Then it gets tricky. Didn't know you could use "exists" to check whether a path points to an external paper file. That's indeed the case - those "paper folders" belong to a proprietary software of a recording studio, they hold takes and tracks, references to thousands of small wav-files. I just abuse them as paperfolders. But XY doesn't leave them in UTF-8. To counter this, I am working on a script that re-codes them back to UTF-8 whenever I have them on display.

The other thing I take along from your help is resolvepath() - one of those commands I had skimmed over every so often, never really grasping what it's for. Now in hindsight, it suddenly reconnects to what SkyFrontier had started out with. It's mind-boggling to see this approach working out so well, coming full circle from tab caption to full name.

Thank you both. Awesome help, awesome forum. :tup:

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: Check if paperfolder active

Post by klownboy »

Cool Sammay, handy use of SC resolvepath. I thought the use of SC exists on 'paper' sounded familiar. I got into that topic with you and Don here http://www.xyplorer.com/xyfc/viewtopic. ... er#p114751 At the time, I was writing a change to ThumbnailMaintenance script which would recognize/account for paper in the thumbnail cache files. Don ended up tweaking SC exists to recognize 'paper' (i.e., to treat paper as a folder).

Stef123

Re: Check if paperfolder active

Post by Stef123 »

A prime example for illustrating the benefits of a forum. Provided it is well maintained and kept alive by an active community of users. I like these dynamics when one thing leads to another.

@Ken
Good thing you pointed that out half a year ago, laying the groundwork with the extended use of "exists". I just wonder why that thread didn't come up when I searched for it, probably because I searched for paperfolder instead of just "paper".

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: Check if paperfolder active

Post by klownboy »

It is a great forum. I have XY bookmarks up the kazoo. Unfortunately too many to easily use and find things quickly. I really need to categorize them into separate folders or sub-folders.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Check if paperfolder active

Post by bdeshi »

just a note, I've not used exists() on the paper:-formatted path, but on the papername only, to check if it's not a <xypaper>-relative paper path. :wink:
Stef123 wrote:I just wonder why that thread didn't come up when I searched for it, probably because I searched for paperfolder instead of just "paper".
I always get far better results using google. Case in point: https://www.google.com/search?q=site:xy ... per,exists the first result (at least in my locale) is Ken's referenced topic.
I have this set up as a search provider with xyfc keyword
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply