How to execute command from popupmenu return string

Discuss and share scripts and script files...
Post Reply
jaywalker32
Posts: 205
Joined: 27 May 2014 05:24

How to execute command from popupmenu return string

Post by jaywalker32 »

I'm trying to setup a custom popupnested menu which can have button commands (like :viewthumbs) or normal commands (like #306)

I don't want to execute the commands directly from the popup menu, but instead read the selected menu item, then decide whether to execute it or not:

Code: Select all

$a = readfile("<xydata>\filters.txt");    
  $fil = popupnested($a);
  if ($fil != ""){  
  	if(gettoken($fil, 1,"") == "§"){
  		execute $fil; //$fil = #306 or $fil = :viewthumbs
  	}	
  	else{
    	filter $fil, 8;
    }
  }



My problem is, how do I 'execute' whatever is in $fil?

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: How to execute command from popupmenu return string

Post by highend »

Don't know what button commands are but you can execute internal (#...) commands via

Code: Select all

goto #<command id>;
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: How to execute command from popupmenu return string

Post by bdeshi »

button commands with

Code: Select all

button regexreplace(<button>, "^:");
// Use just the text part of the button name. The colon is only needed for using that button's icon.
// eg, button 'viewthumbs';
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: How to execute command from popupmenu return string

Post by bdeshi »

In fact, here's a better example. Check whether the $fil var has # or : at start and either run a command or trigger a button.
However, it looks like your $fil already has a '§' marker at the beginning, so we have to trim this before executing the command:

Code: Select all

if (gettoken($fil, 1,"") == "§"){
  $fil = substr($fil, 1);           // trim the first char ("§" marker) of $fil
  switch substr($fil,, 1) {         // get starting char of $fil, this should be now be # or :
  case '#':                         // in case it's # ...
    load $fil,, 's'; break;         // run the #command
  case ':':                         // in case it's : ...
    button substr($fil, 1); break;  // trigger the button (but we don't want the : here)
  }
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

jaywalker32
Posts: 205
Joined: 27 May 2014 05:24

Re: How to execute command from popupmenu return string

Post by jaywalker32 »

Thanks! It works. In fact, it seems that 'button' works for both cases, so no need to check whether it's # or :

Nvm, it was executing it directly from the popup. The switch..case still works tho.

Post Reply