Create new txt file containing clipboard contents
-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Create new txt file containing clipboard contents
Hi there, I know I'm probably missing something really obvious but how would I create a new text file that contains the current contents of the clipboard? Cheers.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
admin
- Site Admin
- Posts: 67269
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Create new txt file containing clipboard contents
Edit / Paste Special / Paste Text Into File
FAQ | XY News RSS | XY X
-
LittleBiG
- Posts: 1848
- Joined: 08 Apr 2011 12:57
- Location: Win10x64
Re: Create new txt file containing clipboard contents
Code: Select all
writefile("clip.txt", "<clipboard>");-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Create new txt file containing clipboard contents
Thanks LittleBiG, That command didn't even occur to me 
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Create new txt file containing clipboard contents
Hi again, When the text file is created what is the code to have it selected for rename like the 'new' command parameter? I can get the file selected (highlighted) but not for rename (as in pressing F2). Cheers.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Create new txt file containing clipboard contents
When you've highlighted it (by sel()), did you place the focus on the correct pane?
One of my scripts helped you out? Please donate via Paypal
-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Create new txt file containing clipboard contents
Hi highend, I can't remember what I tried but I know I didn't use a focus command. And I think I tried using 'selectitems' and not 'sel'.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Create new txt file containing clipboard contents
I still cannot figure out how to make the selection work. Please help!!
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Create new txt file containing clipboard contents
Then show us your code?
One of my scripts helped you out? Please donate via Paypal
-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Create new txt file containing clipboard contents
Sorry highend, I kept deleting the code I was trying and starting again
But about 2 minutes after I posted I found some code in another thread and now, YAY, I have this working:
Now my next question is, I have writefile set to rename on collision so how would I make selectitems apply to the renamed file?
Code: Select all
writefile("new text file.txt", "<clipboard>", r);
focus(list);
#485; //F5 Refresh File List
sel 1; selectitems "new text file.txt";
#172; //F2 RenameWindows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
admin
- Site Admin
- Posts: 67269
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Create new txt file containing clipboard contents
Ahem, did anybody see my post? This is built in since many years ago.admin wrote:Edit / Paste Special / Paste Text Into File
FAQ | XY News RSS | XY X
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Create new txt file containing clipboard contents
Read the help entry for writefile()?Now my next question is, I have writefile set to rename on collision so how would I make selectitems apply to the renamed file?
So you can get the (modified) name via a gettoken on the variable name.Usage
WriteFile() is implemented as a function (instead of a statement) because the return value can be useful. You may, however, call functions without using a dummy variable. See examples below.
Example with on_exist = "r"
For example, if "a.txt" exists in the current folder, a new file "a-01.txt" is created if the Incremental Affix is "-01":
text writefile("a.txt", "ab", "r");
The text window will shown a return like this including the full filename. The "5" (1 OR 4) means "data written" and "file was renamed": 5|E:\Test\a\K\1-01.txt
@Don
Small mistake in the help file
The return value should be:The text window will shown a return like this including the full filename. The "5" (1 OR 4) means "data written" and "file was renamed": 5|E:\Test\a\K\1-01.txt
5|E:\Test\a\K\a-01.txt
One of my scripts helped you out? Please donate via Paypal
-
admin
- Site Admin
- Posts: 67269
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Create new txt file containing clipboard contents
Thanks for the Help hint.
FAQ | XY News RSS | XY X
-
kiwichick
- Posts: 738
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Create new txt file containing clipboard contents
Sorry highend, I've had a look at gettoken in the help file but I can't see how I apply it to the script I already havehighend wrote:So you can get the (modified) name via a gettoken on the variable name.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Create new txt file containing clipboard contents
Code: Select all
$fileName = "new text file.txt";
$modFileName = writefile($fileName, "<clipboard>", r);
$fileName = (gettoken($modFileName, 2, "|") != "") ? gettoken($modFileName, 2, "|") : $fileName;
focus(list);
#485; //F5 Refresh File List
sel 1; selectitems $fileName;
#172; //F2 RenameOne of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club