[Scripting help] Open file / target shortcut

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
nav
Posts: 20
Joined: 14 Mar 2013 21:44

[Scripting help] Open file / target shortcut

Post by nav »

Hi, i want to add usercommand/script file that do the function "edit with notepad++",which will open current file in notepad++
i use this command

Code: Select all

open """C:\Program Files\Notepad++\notepad++.exe"" ""<curitem>""";
But it has problem if the file is shortcut (.lnk) file, it will open the shortcut file in notepad++ ,while i want it open the file (the target of shortcut)
I think i have to make xy do this
if not shortcut file then open it
if shortcut then open target
but i don't know how to do it

Any help would be much appreciated
Thanks

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

Re: [Scripting help] Open file / target shortcut

Post by highend »

Code: Select all

    $curItem = "<curitem>";
    $shortcut = property("#ShortcutTarget");
    if ($shortcut) { $curItem = $shortcut; }
    open """C:\Program Files\Notepad++\notepad++.exe"" ""$curItem""";
One of my scripts helped you out? Please donate via Paypal

nav
Posts: 20
Joined: 14 Mar 2013 21:44

Re: [Scripting help] Open file / target shortcut

Post by nav »

highend wrote:

Code: Select all

    $curItem = "<curitem>";
    $shortcut = property("#ShortcutTarget");
    if ($shortcut) { $curItem = $shortcut; }
    open """C:\Program Files\Notepad++\notepad++.exe"" ""$curItem""";
Thank you so much,it works like a charm :)

nav
Posts: 20
Joined: 14 Mar 2013 21:44

Re: [Scripting help] Open file / target shortcut

Post by nav »

highend wrote:

Code: Select all

    $curItem = "<curitem>";
    $shortcut = property("#ShortcutTarget");
    if ($shortcut) { $curItem = $shortcut; }
    open """C:\Program Files\Notepad++\notepad++.exe"" ""$curItem""";
may i ask for advance feature ,like that
with media player, there is /add parameters sothat we can add files to playlist

Code: Select all

 open """C:\Program Files\The KMPlayer\KMPlayer.exe"" /ADD ""$curItem""";
but yours and the above code only works with single item ,may i ask for multiple items (detect shortcuts /files of the current selected items) ?
i tried to put foreach but not succeed

Code: Select all

	foreach($item, "<get SelectedItemsPathNames |>") {
	$item = "<item>";
	$shortcut = property("#ShortcutTarget");
	if ($shortcut) { $item = $shortcut; }
	open """e:\Program Files\foobar2000\foobar2000.exe"" /ADD ""$item""";
	}

sorry i'm greedy :mrgreen:
Thanks alot
Last edited by nav on 19 Oct 2015 18:56, edited 1 time in total.

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

Re: [Scripting help] Open file / target shortcut

Post by highend »

That makes 20$... Just because it's so ultra-advanced!

Code: Select all

    $items = "";
    foreach($item, "<get SelectedItemsPathNames |>") {
        if (exists($item) != 1) { continue; }
        $shortcut = property("#ShortcutTarget", $item);
        if ($shortcut) { $item = $shortcut; }
        $items = $items . quote($item) . " ";
    }
    open """C:\Program Files\The KMPlayer\KMPlayer.exe"" /ADD $items";
One of my scripts helped you out? Please donate via Paypal

nav
Posts: 20
Joined: 14 Mar 2013 21:44

Re: [Scripting help] Open file / target shortcut

Post by nav »

highend wrote:That makes 20$... Just because it's so ultra-advanced!

Code: Select all

    $items = "";
    foreach($item, "<get SelectedItemsPathNames |>") {
        if (exists($item) != 1) { continue; }
        $shortcut = property("#ShortcutTarget", $item);
        if ($shortcut) { $item = $shortcut; }
        $items = $items . quote($item) . " ";
    }
    open """C:\Program Files\The KMPlayer\KMPlayer.exe"" /ADD $items";
Thanks again,you're so quick , i 've just found your code at

http://www.xyplorer.com/xyfc/posting.ph ... 3&p=115566
highend wrote:By base name you mean: the name of the file (incl. the extension) without it's path?

Code: Select all

    foreach($item, "<get SelectedItemsPathNames |>") {
        $baseName = getpathcomponent($item, "file");
        run """program.exe"" -option1 ""$baseName"" -option2 ""$item""";
        wait 50;
    }
Otherwise you have to replace "file" with "base" if it's really the base name (without extension and path)...
i tried editing but not success ,then coming back and i saw your new post
you made my day :mrgreen: :mrgreen:

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: [Scripting help] Open file / target shortcut

Post by kotlmg »

Code: Select all

    $items = "";
    foreach($item, "<get SelectedItemsPathNames |>") {
        if (exists($item) != 1) { continue; }
        $shortcut = property("#ShortcutTarget", $item);
        if ($shortcut) { $item = $shortcut; }
        $items = $items . quote($item) . " ";
    }
    open """C:\Program Files\The KMPlayer\KMPlayer.exe"" /ADD $items";
[/quote]


small request

in the above code if some of the selected files are not a media files they should not be added to the list. is it possible? as of now there is one command "Select By Selected Type(s) Ctrl+Alt+M" #254 is available. i want to select all media files at once.

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

Re: [Scripting help] Open file / target shortcut

Post by highend »

Code: Select all

    $gfts  = "|" . replace(get("genericfiletype", "{:Media}", "|"), "*.") . "|";
    $items = "";
    foreach($item, <get SelectedItemsPathNames |>) {
        if (exists($item) != 1) { continue; }
        $shortcut = property("#ShortcutTarget", $item);
        if ($shortcut) { $item = $shortcut; }
        if (strpos($gfts, "|" . gpc($item, "ext") . "|") == -1) { continue; }
        $items .= quote($item) . " ";
    }
    if ($items) { open """C:\Program Files\The KMPlayer\KMPlayer.exe"" /ADD $items"; }
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: [Scripting help] Open file / target shortcut

Post by kotlmg »

thanks a lot for the above code. if we select media and pdf and .xys files etc, it is not able to filter pdf files, .xys files ,. i want all files other than media files to be filtered. if i select only pdf files and .xys then your code is perfectly working. please see.

Code: Select all

    "Potplayer..."
    $gfts  = "|" . replace(get("genericfiletype", "{:Media}", "|"), "*.") . "|";
    $items = "";
    foreach($item, <get SelectedItemsPathNames |>) {
        if (exists($item) != 1) { continue; }
        $shortcut = property("#ShortcutTarget", $item);
        if ($shortcut) { $item = $shortcut; }
        if (strpos($gfts, "|" . gpc($item, "ext") . "|") == -1) { continue; }
        $items .= quote($item) . " ";
    }
    if ($items) { OpenWith """C:\Program Files (x86)\The Kmplayer\PotPlayerMini64.exe"" $items"; }




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

Re: [Scripting help] Open file / target shortcut

Post by highend »

if some of the selected files are not a media files they should not be added to the list
And that's exactly what the code does.

Code: Select all

@Test.xys
ATEN VS481C.pdf
Bette Midler - From A Distance.mkv
bosch-glm-500-professional.pdf
Celtic Woman - Beyond the Sea.mp4
Celtic Woman - May It Be.flv
Debian - Xfce installation.txt
keyboard shortcuts for Windows.txt
Result:

Code: Select all

"R:\Bette Midler - From A Distance.mkv" "R:\Celtic Woman - Beyond the Sea.mp4" "R:\Celtic Woman - May It Be.flv" 
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: [Scripting help] Open file / target shortcut

Post by kotlmg »

it is not working. i dont know where i am going wrong.
C:\Users\M.K.RAO\Downloads\PlayWithMedia.xys
C:\Users\M.K.RAO\Downloads\PlayWithMedia - Copy.xys
C:\Users\M.K.RAO\Downloads\Open pdf.xys
C:\Users\M.K.RAO\Downloads\WhatsApp Video 2022-01-15 at 18.23.55.mp4
C:\Users\M.K.RAO\Downloads\VMV Q 06 2021-22.pdf
C:\Users\M.K.RAO\Downloads\CIU QUOTATION.pdf

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

Re: [Scripting help] Open file / target shortcut

Post by highend »

Then step through the code and find what's not working?
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: [Scripting help] Open file / target shortcut

Post by kotlmg »

it is not working.
D:\AVI\Chapter 10 Exercise Class 7 _ Sanskrit Ruchira Part 2 _ Studyment.mp4
D:\AVI\#Day7.2 ll AP & GP Special Tricks.mp4
D:\AVI\Loss Belly Fat in one week at Home _ Belly Fat burning workouts Telugu.mp4
D:\AVI\external tools in emeditor.pdf
D:\AVI\sanscrit excersizes.pdf

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: [Scripting help] Open file / target shortcut

Post by kotlmg »

after properly indenting the code, is is working perfectly. thanks a lot.

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: [Scripting help] Open file / target shortcut

Post by kotlmg »

in the above code, if i have to open only pdf files and nothing else with pdf viewer, then how i should modify the generic file extension to pdf files?

Post Reply