A feature for "New Items"

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

A feature for "New Items"

Post by MBaas »

Disclaimer: I attempted to search the forum, but a search for "New Items" ignored the word "New" and I did not like the idea of browsing through 9k matches. Pls. forgive me if it has been asked before ;)

I like the idea of "New Items" - but I would like to have it extended to run a script after creation of the new item(s). Ideally the script would depend on the selected item, ie. if I choose "foo.txt" as the "New Item", I'd like "foo.txt.xys" to be executed. And it should be able to access the filename of the new file that was created.

Is something like that doable already?
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: A feature for "New Items"

Post by highend »

No, at least not if you don't implement your own "New Items" (scripted) version of it
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: A feature for "New Items"

Post by highend »

Copy the Show new items in popup menu_v0.1.xys into your XY scripts folder (and remove the version information if you want)

Create a new subfolder in your XY scripts folder named "new_items"
Copy the !Generic_v0.1.xys into that one AND remove the version information from it!

Now make a copy of !Generic.xys and name it e.g. Word document.docx.xys IF one of your new item entries is Word document.docx
Edit that new script and do whatever you want with that file in this part of the script (near the bottom):

Code: Select all

    // Select item and go into renaming mode
    focus "L";
    selectitems $dstItem;
    #172; // Rename selected item
$dstItem contains the full path of the new file before you do anything with it...

How you invoke the Show new items in popup menu_v0.1.xys is up to you,
I do it with a "custom event action right-click on white in list" script...
To see the attached files, you need to log into the forum.
One of my scripts helped you out? Please donate via Paypal

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: A feature for "New Items"

Post by LittleBiG »

(Warning! The post below may contain traces of joke. Do not take it seriously.)

What a sloppy coding. I did have to correct it: echo "Item has not appeared after " . $waitTime/1000 . " second(s), aborted!"; It makes all the difference.

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

Wow, highend - THANKS VERY MUCH - what a great start into a productive new year!!! :appl: :appl: :appl:
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: A feature for "New Items"

Post by LittleBiG »

MBaas wrote: ↑05 Jan 2021 14:08 Wow, highend - THANKS VERY MUCH - what a great start into a productive new year!!! :appl: :appl: :appl:
Indeed :appl:

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

Highend - I might be too stupid to use it, but here's what's happening:

after launching the script (via CEA on right-click white), an error comes up:
05-01-_2021_14-32-24.png


(It does not matter if I choose a "New thing" for which I have a script or not.)

The script worked once and I was able to create a new file. I then copied !Generic.xys to .mipage.xys and this error showed up. (As mentioned, also for any unscripted new items.) So I moved that script out of sight - so things should be back in their original state (I did not touch your scripts!).

Aha - a restart fixed the problem. It seems to be gone! (Am I struggling with temporary fluctuation of the time-continuum or is there an explanation for this (other than my mental state) ?)
To see the attached files, you need to log into the forum.
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

And a practical question - since I never saw that merge of scripting commands with the menu-refs, like you did in Generic.xys:

When I tried to add code after the user has chosen a name (with #172), I found that the script no longer waited for user-input. Is there a way to achieve that? (I'm currently using $new = input("Name new file",,,"s"); to query it, but of course #172 looks nicer, as it happens directly inside XY's UI ;) )
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: A feature for "New Items"

Post by highend »

Because of that I've stated:
$dstItem contains the full path of the new file before you do anything with it...
If you don't want to use $new = input("Name new file",,,"s");

you'd need to go into a waiting loop again, looking for all files with the same extension (it's unlikely that you've chosen a new item like e.g. .docx and then rename the extension, right?)
and comparing them with the old name (before the renaming) to find out which new name was given after using #172;
One of my scripts helped you out? Please donate via Paypal

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

Ah, I see - thanks! Guess I'll stay with the Input-approach then - it "feels" safer ;)
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

So, finally I don't like the separate input any more, renaming the new thing "in place" (using #172) is so much nicer that I'd like to implement that idea of comparing lists. But I don't see how to do that. In other words: if I have a variable "$l2 = listpane(, , 1+4);", how can I get the difference to list $l1 (which I captured before the operation)?

I could not find any doc that would show handling of lists - and I also tried "sequential reading" instead of search for keywords ;)
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: A feature for "New Items"

Post by highend »

By using a while (true) {} loop like the one already existing
Drop all items from the listpane() capture apart from the one before the rename
and also inside the loop.

And then check if the item that remains is the same like before the rename.
Do it until it reaches a timeout, e.g. 10 seconds and either the item was renamed
until it or you accept that it wasn't renamed at all.

That depends on how you deal with those new items...

$new = input("Name new file",,,"s");
is the better solution because you have the correct name regardless if you hit {enter} immediately of after 20 seconds...
One of my scripts helped you out? Please donate via Paypal

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

Arrgh, you're right, I hadn't thought about that - but it is very likely (especially with this user! ;)) that even seemingly simple "name a file"-operations can turn into a longer process... :roll:
I will have to get used to the popup then :wink:
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

MBaas
Posts: 710
Joined: 15 Feb 2016 21:08

Re: A feature for "New Items"

Post by MBaas »

highend, I thought about it a bit more and think I'm ready to take a risk (and use #172), so I tried to change your template !Generic.xys and turned it into a dedicated script that is (as the only action) called by several extension-related scripts.
I actually changed the logic for the ending of the "wait for rename" a bit to just loop as long as the new file still exists.

But I can't test it, script-execution ends after calling #172! To proof it I added a minor Msg immediately following #172 - it is never shown.

Would you mind having a look whether I did something wrong or why #172 does not hand back control to the script?
ShowNewItems_sub2rename.xys
To see the attached files, you need to log into the forum.
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * F² * LinkTree

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: A feature for "New Items"

Post by highend »

I get the "Still executing!" message so I wonder what's the question here :mrgreen:

Btw,

Code: Select all

    if (true) // choose which renaming-approach you prefer: true=directly in XY, false=popup-dialog
    {
        #172; // Rename selected item
        Msg "Still executing!";  // give a hint that script is still executing!
        $passedTime = 0;
        while (true) {
            end ($passedTime >= $waitTime2), "Item has not appeared after " . $waitTime2 / 1000 . " second(s), aborted!";

            if ($srcType == 2) { $result = listpane(, , 2+4); }
            else               { $result = listpane(, , 1+4); }
            if (!formatlist($result, "F", "|", "$item")) { break; }  // the copied file must disappear from the list!
            $passedTime += 100;
            wait 100;
        }
    } else {
        $new = input("Name new file (NO extension!)",,,"s");// actually it is possible to provide an extension, even a different one. I intentionally allowed that ;)
        selectitems renameitem($new ,, 4);    // rename the file and select it
    }
There is no choice here, true is always true, else will never be called...
One of my scripts helped you out? Please donate via Paypal

Post Reply