 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
exhueydriver
Joined: 12 Jul 2004 Posts: 51 Location: Fife,Wa
|
Posted: Mon Jul 19, 2004 6:19 am Post subject: FileCopy using ClipBoard |
|
|
I've been lurking here for about a week, now, and I have to say,compared to the
"Other" forum I was watching for the last 4 months, this one ACTUALLY wants to
HELP newbies. (the other one's usual answer was RTFM, and I had, several times, but things are not always coherent the first few times around).
My background- 4 1/2 years scripting in FileMaker Pro(database), so I have a feeling
for the basics, just have to learn new syntax.
Which brings me to the question.
One of the limiting things about FMP is, if you want to do a "Scripted"(read: one button click)
Save a File as(or Print to *.pdf), it has to be a Known File Name & Location(i.e. C:\ThisFolder\ThisFile.txt), but if you want to do multiple reports, or invoices or whatever, you need the ability to re-name the last file dynamically, based on a "Field" value of the current record.
So, I made a field whose value is
C:\Discoes2Office\TestOne.txt, C:\Discoes2Office\TestOneCopy.txt
Then I made a FMP script that copies that to the Clipboard, then runs-
and here i have the Problem. If I understand the Clipboard(variable) correctly, the AHK script should be-
FileCopy, %ClipBoard%
BUT, the error I get is "FileCopy requires 2 or more parameters"
If I paste the file path into the AHK script(hard code it), it works fine.
I've tried-
MsgBox, %Clipboard%
to show me what is there,
and it shows what it's supposed to.
No matter what I try(and I've tried a lot), I am missing something.(is it one of those `n or `r things, and where do I put them?)
Thanks
Don |
|
| Back to top |
|
 |
Beastmaster
Joined: 15 Apr 2004 Posts: 182
|
Posted: Mon Jul 19, 2004 8:26 am Post subject: |
|
|
| Quote: | | the other one's usual answer was RTFM |
TBH, if the question would be "How can I read a line from within a file" and the command for it is: FileReadLine , well - I would also think about the above advise
My favourite killer request: "Can someone write me a script" That's an equivalent for "better I'm wasting your time then mine"
For the complete nobs outa there:
To ask the right question: Try to find the "perfect" keyword combination which would descripe the issue - same as if you would have to request it at Google's. That works out fine in ~90%
There's a different if you ask for a "Button" as for a "little square picture at the left of the screen which drives me mad when it prints"
-----
| Quote: | One of the limiting things about FMP is, if you want to do a "Scripted"(read: one button click)
Save a File as(or Print to *.pdf), it has to be a Known File Name & Location(i.e. C:\ThisFolder\ThisFile.txt), but if you want to do multiple reports, or invoices or whatever, you need the ability to re-name the last file dynamically, based on a "Field" value of the current record. |
That's what I read from the above:
a) You want a document "Save(ed) As" aka converted to become a *.pdf file.
Question: what is the source file format ? *.csv; *.txt; *.xls; ... ???
b) The docs naming is based on the content of a specific field of the source document.
-----
If you've to do that on a daily basis, and you would prefer to do it hidden/in the background then you should think about a commandline solution.
I) Loop, Read and StringSplit --> RTFM should make it to get the "filename".
II) Ghostscript and Ghostview are usefull to do the PDF conversion. |
|
| Back to top |
|
 |
Torben Guest
|
Posted: Mon Jul 19, 2004 8:56 am Post subject: |
|
|
I don’t know anything about FileMaker Pro, so I can’t help you with that.
But as you already realised FileCopy requires 2 or more parameters and the line “FileCopy, %ClipBoard%” does not apply to that.
There are at least 3 short cuts that probably can solve your problem.
Assuming your database always hold the filenames in the form you stated: C:\Discoes2Office\TestOne.txt, C:\Discoes2Office\TestOneCopy.txt
AND that this is the content of the clipboard
you can try these solutions:
1. the first one splits the clipboard-string by the comma
| Code: | Comma = ,
StringGetPos, pos, ClipBoard, %Comma%
StringLen, length, ClipBoard
pos2 = -%pos%
pos2 -=2
pos2 +=%length%
StringLeft, FileName1, ClipBoard, %pos%
StringRight, FileName2, ClipBoard, %pos2%
if pos >= 0
MsgBox, %FileName1%`n%FileName2% |
2. This solution manipulates the first filename in the clipboard-string (assuming that the second filename is always the same as the first one except for the “copy”-part of the second name
| Code: | Comma = ,
StringGetPos, pos, ClipBoard, %Comma%
StringLeft, FileName1, ClipBoard, %pos%
StringReplace, FileName2, FileName1, ., Copy., all
if pos >= 0
MsgBox, %FileName1%`n%FileName2% |
3. The third solution uses AHK’s very flexible and easy-to-use array-function:
| Code: | FileName =%ClipBoard%
StringSplit, FileName, Filename,`,
MsgBox, %FileName1%`n%FileName2% |
All 3 solutions might work when you replace the MsgBox-command with FileCopy
/Torben |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Jul 19, 2004 9:03 am Post subject: |
|
|
| Quote: | | All 3 solutions might work when you replace the MsgBox-command with FileCopy |
... and replace the `n with a comma of cource
/Torben |
|
| Back to top |
|
 |
exhueydriver
Joined: 12 Jul 2004 Posts: 51 Location: Fife,Wa
|
Posted: Fri Jul 23, 2004 3:45 am Post subject: |
|
|
Sorry it took so long, but THANKS
Beastmaster- I didn't make myself clear, I don't want to change the file TYPE
(i.e. *.txt ->*.pdf), I only want to re-name (or move) the file, with the same extension.
Torben- Reading your response #3 made me realize my problem. I
*THOUGHT* i was passing 2 parameters
(C:\Discoes2Office\TestOne.txt, C:\Discoes2Office\TestOneCopy.txt ),
but because it was in ONE variable, AHK saw it as only ONE parameter, hence the error of "FileCopy requires TWO or more parameters".
So your
FileName =%ClipBoard%
StringSplit, FileName, Filename,`,
MsgBox, %FileName1%`n%FileName2%
split my 2 parameters into 2 variables, then added them together to make it work. Thanks. Learned something, never used arrays before.
To others searching this post, this script didn't work the first time I tried it.
If you look at
C:\Discoes2Office\TestOne.txt, C:\Discoes2Office\TestOneCopy.txt
there is a space after the comma, and before the "C", AHK didn't like that.
Remove the space, and it works a treat( as the Brits say)
Don |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Jul 23, 2004 4:05 am Post subject: |
|
|
| Quote: | | there is a space after the comma, and before the "C", AHK didn't like that. |
I think what's going on there is that the space is seen as part of the filename, which the OS will say is invalid, thus the operation does not succeed. Normally this isn't an issue since leading and trailing spaces are automatically trimmed from parameters. But in this case, a variable containing a literal leading space is used, which is why it's a problem. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|