Page 1 of 2
A feature for "New Items"
Posted: 04 Jan 2021 15:25
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?
Re: A feature for "New Items"
Posted: 04 Jan 2021 15:57
by highend
No, at least not if you don't implement your own "New Items" (scripted) version of it
Re: A feature for "New Items"
Posted: 05 Jan 2021 11:28
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...
Re: A feature for "New Items"
Posted: 05 Jan 2021 12:56
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.
Re: A feature for "New Items"
Posted: 05 Jan 2021 14:08
by MBaas
Wow, highend -
THANKS VERY MUCH - what a great start into a productive new year!!!

Re: A feature for "New Items"
Posted: 05 Jan 2021 14:27
by LittleBiG
MBaas wrote: ↑05 Jan 2021 14:08
Wow, highend -
THANKS VERY MUCH - what a great start into a productive new year!!!
Indeed

Re: A feature for "New Items"
Posted: 05 Jan 2021 14:42
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) ?)
Re: A feature for "New Items"
Posted: 05 Jan 2021 15:19
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

)
Re: A feature for "New Items"
Posted: 05 Jan 2021 15:36
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;
Re: A feature for "New Items"
Posted: 05 Jan 2021 15:55
by MBaas
Ah, I see - thanks! Guess I'll stay with the Input-approach then - it "feels" safer

Re: A feature for "New Items"
Posted: 09 Jan 2021 12:25
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

Re: A feature for "New Items"
Posted: 09 Jan 2021 13:07
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...
Re: A feature for "New Items"
Posted: 09 Jan 2021 13:14
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...
I will have to get used to the popup then

Re: A feature for "New Items"
Posted: 10 Jan 2021 12:55
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
Re: A feature for "New Items"
Posted: 10 Jan 2021 13:43
by highend
I get the "Still executing!" message so I wonder what's the question here
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...