Page 1 of 2

Script to remove tags by inputselect

Posted: 24 Sep 2012 12:28
by kiwichick
Hi there, I've written a script that will list the tags of the selected item in an inputselect window. The tags can be selected via checkbox and the selected tags are to be removed. The only problem is it won't remove the item's final tag. So if an item has 7 tags it will remove any of the first 6 but not the last one. Can someone please tell me why and how to fix it? Cheers.

Code: Select all

//doesn't remove last existing tag
$a = report("{tags}<crlf>", 1);
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", $a,", ",2);
   tag "$b", ,1,2;

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 12:35
by Marco
Try this ;)

Code: Select all

//doesn't remove last existing tag
$a = report("{tags}", 1);
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", $a,", ",2);
   tag "$b", ,1,2;

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 12:51
by kiwichick
Thanks heaps Marco, Gosh it's the littlest things sometimes. So much to learn :shock:

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 15:03
by LittleBiG
Marco wrote:Try this ;)

Code: Select all

//doesn't remove last existing tag
$a = report("{tags}", 1);
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", $a,", ",2);
   tag "$b", ,1,2;
It doesn't seem ok. Try this instead:

Code: Select all

//tag remove  
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", formatlist(report("{tags}, ", 1),"eds",", "),", ",2); 
   if $b != "" {tag "$b", ,1,2};

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 15:11
by Marco
LittleBiG wrote:It doesn't seem ok...
I can confirm that it works.

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 15:19
by LittleBiG
Marco wrote:
LittleBiG wrote:It doesn't seem ok...
I can confirm that it works.
I have 3 files with 3 different tags. (1 file - 1 tag). Your script concatenates my 3 tags, then gives me 1 choice to remove.

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 15:29
by Marco
LittleBiG wrote:I have 3 files with 3 different tags. (1 file - 1 tag). Your script concatenates my 3 tags, then gives me 1 choice to remove.
You're doing it wrong, the script is intended to work on a single file/folder.
...a script that will list the tags of the selected item in an inputselect window...

Code: Select all

...Tags will be removed from the selected File or Folder...

Re: Script to remove tags by inputselect

Posted: 24 Sep 2012 15:34
by LittleBiG
Ok, I see.

Re: Script to remove tags by inputselect

Posted: 25 Sep 2012 01:10
by kiwichick
OMG LittleBiG!!! Thank you so so so much :appl: Yes my script concatenates the tags when multiple selections are made. That's why, as Marco pointed out, it's only intended to work on one file or folder. My next mission was to see if I could work out how to make it work on multiple selections (and then concede defeat and post back here with a request) :oops: But you've done it for me - and probably saved me hours of trying. Absolutely loving XYplorer!!!!!!!

Re: Script to remove tags by inputselect

Posted: 26 Sep 2012 00:52
by kiwichick
OK the script as it is will remove tags from selected item(s) only which means if a folder is selected only the folder itself is affected and not recursively (the folder contents). So I've managed to incorporate part of this script with part of another script I have that will remove tags recursively and it works a treat!!!

Code: Select all

"Remove inputselect Tags recursively|:tagsrmv"
   end(getinfo("CountSelected") < 1), "At least one item must be selected!";
   $lstF = get(selecteditemspathnames);
   $a = inputselect("Select Tags to Remove.<crlf> Tags will be removed recursively (selected files, folders and folder contents).", formatlist(report("{tags}, ", 1),"eds",", "),", ",2);
   foreach ($tkF, $lstF, "<crlf>") {
   tag "$a", "$tkF", 1, 2;
   $lst = folderreport("items", "r", $tkF, "r");
   foreach ($tk, $lst, "<crlf>") {
   tag "$a", "$tk", 1, 2;
   }
   tag "$a", "$tkF", 1, 2;
   }
The next evolution I've been trying to figure out is, inputselect shows the tags of the selected items only. If a folder is selected sometimes the contents will have different tags to the folder and I would like to have these tags shown by inputselect as well. As always any help you guys provide is gratefully accepted :biggrin:

Re: Script to remove tags by inputselect

Posted: 26 Sep 2012 09:17
by highend

Code: Select all

"Remove inputselect Tags recursively|:tagsrmv"
   end(getinfo("CountSelected") < 1), "At least one item must be selected!";
   $lstF = get("selecteditemspathnames", "|");

   $tagLst = "";
   $filesLst = "";
   foreach($item, $lstF, "|") {
		if(exists($item) == 2) {
			$tags = folderreport("files:{tags}", "r", $item, "r", , "|");
			$files = folderreport("files", "r", $item, "r", , "|");
		} else {
			$tags = report("{tags}", $item);
			$files = $item;
		}
		$tagLst = $tagLst . $tags . "|";
		$filesLst = $filesLst . $files . "|";
   }
   $tagLst = replace($tagLst, ",", "|");
   $tagLst = formatlist($tagLst, "edst", "|"); // Clean the tag list

   $a = inputselect("Select Tags to Remove.<crlf> Tags will be removed recursively (selected files, folders and folder contents).", $tagLst, "|" , 2);
   tag "$a", $filesLst, 1, 2;

Re: Script to remove tags by inputselect

Posted: 26 Sep 2012 11:11
by kiwichick
OMG almost, highend!!! It removes tags from the selected folder's contents recursively YAY! Except, if the selected folder contains a subfolder, tags are removed from the subfolder's contents but not the subfolder itself.

Re: Script to remove tags by inputselect

Posted: 26 Sep 2012 11:37
by highend
Then replace the "files" with "items" in the folderreport() commands?

Re: Script to remove tags by inputselect

Posted: 26 Sep 2012 11:55
by kiwichick
Yes that removes tags from the selected folder's contents including subfolders but it doesn't remove tags from the selected folder :?

Re: Script to remove tags by inputselect

Posted: 26 Sep 2012 12:08
by highend
Which is a completely different issue than your last post.

Include the the parent folder via:

Code: Select all

			$tags = report("{tags}", $item) . "|" . folderreport("items:{tags}", "r", $item, "r", , "|");
			$files = $item . "|" . folderreport("items", "r", $item, "r", , "|");