Bash: get name of selected item of the desktop


#1

Is it possible to get the name of the selected item on the desktop using the right mouse button (file and path)?

My plan and idea is to run a script with the selected file.

Example:

“mogrify -normalize $selectedfile"
or
"mogrify -rotate 90 $selectedfile”

Greetings Lelldorin


#2

Sounds like a perfect use case for TrackerScript, a TrackerAddon that will run a customized script on the selected items.
It use attribute to specify the script command.

See the recent discussion about Font Install traker add-on:


#3

I think this is what you want:

hey Tracker get Selection of Poses of Window 0


#4

Again I feel I’m missing something, but what’s wrong with drag&drop? Doesn’t a YAB app accept files dropped on either its icon or an open window? That’s how I specify files for almost everything I do.


#5

yab does that just fine, I have used it in the past and am using it in my WebViewer app.

The Tracker add-on CopyNameToClipboard seems to be what lelldorin is looking for.


#6

No i want to use it diectly and not to use another app to get the name and path.

Right click/menu option:imagemagick/flip image for example


#7

On an open window, yes. You need to specify a specific view as the dropzone and then just keep looking for the appropriate message$ code in your main loop.

On the icon … Don’t know, I’ve never tried that, but peek$(“refsreceived”) might pick that up.


#8

I does not want to make a second Imagemagick gui. I only want to make it possible to do fast image manipulation using the context menu. Imagemagick use a dropzone to open images.


#9

Is this the correct string? I will take a look.


#10

Give a look at TrackerScript. Should be easy to duplicate it with different script command and call it “Flip image”.
Don’t forget to set accepted MIME type to image/*, though.


#11

[code]#include <Clipboard.h>
#include <Entry.h>
#include <Path.h>
#include <String.h>
#include <TrackerAddon.h>

void process_refs(entry_ref dir_ref, BMessage *msg, void *) {

BString ClipString;
 	BPath path; 

 	int refs;
 	entry_ref file_ref; 

for( refs=0; msg->FindRef(“refs”, refs, &file_ref)==B_NO_ERROR; refs++) {
BEntry(&file_ref).GetPath(&path);

 if (refs>0) ClipString.Append(" "); 

 BString FileString = filenameonly ? path.Leaf() : path.Path(); 
 bool quote = (FileString.FindFirst(" ") != B_ERROR ); 

 if (quote) ClipString.Append("\"").Append(FileString).Append("\""); 
 else ClipString.Append(FileString); 

}

commandline = new BString("mogrify -flip "+BEntry);
[/code]

Will this be run?
How i can get the header files?


#12

Using makefile-engine (copy skeleton Makefile from /boot/system/develop/etc/Makefile) it should be easy to build your code.

Some issues in your code:

  • last line is buggy, it’s not BEntry but ClipString you want to concatenate to the mogrify -flig string.
  • refs could be a directory too.