Multi Commander Support Forum

Multi Commander => Support and Feedback => Topic started by: karthik on January 18, 2013, 08:46:33

Title: Copying path to clipboard with forward slashes
Post by: karthik on January 18, 2013, 08:46:33
When we do a Ctrl+P, it copies the entire path to clipboard with backward slashes like C:\Users\Karthik\.. etc. Is there a way to copy the path with forward slashes like this C:/Users/Karthik/...

Since I am using this path in unix machines, having forward slashes will help greatly instead of me doing a find replace everytime.

Thanks.
Title: Re: Copying path to clipboard with forward slashes
Post by: Jungle on January 18, 2013, 09:25:17
MultiScript?
Title: Re: Copying path to clipboard with forward slashes
Post by: karthik on January 18, 2013, 09:33:13
Any pointers on how I could start?
Title: Re: Copying path to clipboard with forward slashes
Post by: Jungle on January 18, 2013, 10:45:40
Any pointers on how I could start?
Multi Commander Documentation (http://multicommander.com/docs) > User Defined Commands and Scripting
Title: Re: Copying path to clipboard with forward slashes
Post by: karthik on January 18, 2013, 11:16:51
I tried the following but doesn't seem to work:

@var $arr GetSelectedPaths();
LogDump($arr);
$arr = StrReplace($arr, "\" , "/");
SetClipboardText($arr);

In general, how do I debug a script. Where does the LogDump dump the output?
Title: Re: Copying path to clipboard with forward slashes
Post by: Jungle on January 18, 2013, 12:24:49
1. There is Multi-Script Debugger under Help menu
2. To see output in the Log window you should use Log function
3. $arr is Array, so in order to use it with StrReplace function you should either convert it to string or go through array in a loop.

UPD. Unfortunately, StrLinesArray2String function doesn't work for me, or maybe i use it incorrectly. So, probably, the only way is to make a loop. Maybe Mathias has the right solution.
Title: Re: Copying path to clipboard with forward slashes
Post by: Mathias (Author) on January 18, 2013, 13:07:18
Try this.

@var $arr = GetSelectedPaths();
@var $str = StrLinesArray2String($arr);
$str = StrReplace($str, "\" , "/");
SetClipboardText($str)


(You can compress it into two lines.)
@var $arr = GetSelectedPaths();
SetClipboardText( StrReplace( StrLinesArray2String( $arr ) , "\" , "/" ) );
Title: Re: Copying path to clipboard with forward slashes
Post by: Jungle on January 18, 2013, 13:13:48
@var $str = StrLinesArray2String($arr);

That is why it didn't work for me. Declaration in the docs (http://multicommander.com/docs/multiscript/functions/array#strlinesarry2string) differs:

Code: [Select]
<str> StrLinesArray2String(<array> input, <num> eol);
Title: Re: Copying path to clipboard with forward slashes
Post by: Mathias (Author) on January 18, 2013, 13:30:20
Second parameter is optional so should work both with and without it.

(I will update the doc abort it being optional. )
Title: Re: Copying path to clipboard with forward slashes
Post by: Jungle on January 18, 2013, 13:39:46
Second parameter is optional so should work both with and without it.

Very strange - now it works. Some time ago i got Error -1.
Title: Re: Copying path to clipboard with forward slashes
Post by: karthik on January 18, 2013, 15:15:23
Thanks, Mathias and Jungle.

I can write similar scripts to get finename alone, path alone, etc. And I can assign shortcut hotkeys to these. suppose I assign the default
(Ctrl+P, Ctrl+Shift+P, Alt+Shift+P) shortcuts will it create any problems in terms of MC working and functions?

Is there a way by using multiscript I can get the output of Ctrl+P or Ctrl+Shift+P? In that case, I can use that (instead of GetSelectedPaths()) and replace the backward slashes by forward slashes.

Thanks.
Title: Re: Copying path to clipboard with forward slashes
Post by: Mathias (Author) on January 22, 2013, 15:00:40
See Doc (http://multicommander.com/docs/multiscript/functions/getfilefromview) lots of function for getting different filename part

GetTargetFocusName() / GetTargetFocusName() will give you the current file that are in focus, without path


Title: Re: Copying path to clipboard with forward slashes
Post by: karthik on January 23, 2013, 05:31:58
Thanks Mathias.

This works fine but when I select the ".." directory and execute this script I do not get the source path. Where as when I do Ctrl+P when ".." is selected I get the source path. Is there a way to modify the script to get the source path even for ".." directory with this script?

Essentially I am trying to have a replacement for Ctrl+P and make the script do whatever Ctrl+P will do but with forward slashes instead of backward slashes.

Thanks.
Title: Re: Copying path to clipboard with forward slashes
Post by: Mathias (Author) on January 23, 2013, 07:21:32
Thanks Mathias.

This works fine but when I select the ".." directory and execute this script I do not get the source path. Where as when I do Ctrl+P when ".." is selected I get the source path. Is there a way to modify the script to get the source path even for ".." directory with this script?

Essentially I am trying to have a replacement for Ctrl+P and make the script do whatever Ctrl+P will do but with forward slashes instead of backward slashes.

Thanks.


If current item is the ".." item then get current path else get full path with filename, just like Ctrl+P

Code: [Select]
@var $path = GetSourceFocusName();

if( StrIsEqual($path,"..") )
{
   $path = GetSourcePath();
}
else
{
  $path = GetSourceFocusPath();
}
Title: Re: Copying path to clipboard with forward slashes
Post by: karthik on January 23, 2013, 07:35:19
That helps a lot. Thanks much.