Re: a script for saving text from the clipboard to a file
Re: a script for saving text from the clipboard to a file
- Subject: Re: a script for saving text from the clipboard to a file
- From: Malcolm Fitzgerald <email@hidden>
- Date: Wed, 29 Mar 2006 08:31:40 +1000
On 28/03/2006, at 6:55 PM, Gary (Lists) wrote:
"Paul Berkowitz" wrote:
On 3/27/06 7:20 PM, "Malcolm Fitzgerald" <email@hidden>
wrote:
On 28/03/2006, at 12:47 PM, Diane wrote:
I am a newbie trying to make an Applescript to attach to a FileMaker
button. I'm pretty stuck at this point. I have cobbled together a
script that runs in Script Editor but seems unacceptable to
FileMaker,
which tells me "Expected end of line, etc. but found identifier."
and
will not save my clumsy script (below).
This is your problem:
write clipboard_contents to alias the_path starting at eof
FMP defines WRITE in it's own dictionary and there is a clash because
you are wanting to use Standard Additions write command
You need to use the raw applescript codes for that command.
Standard Additions read/write
-- «event rdwrwrit» -- write
-- «event rdwrread» -- read
«event rdwrwrit» clipboard_contents to alias the_path starting at eof
A less cumbersome way to do it is to "farm" out the file writing to a
handler:
set f to open for access alias thePath with write permission
tell app "FileMake Pro"
set clipboard_contents to whatever
my writeToFile(clipboard_contents, f)
end tell
on writeToFile(someText, f)
write someText to f starting at eof
end writeToFile
Note that since you're writing to f outside an application tell block
you also
need to set f to open for access outside any tell block. Otherwise,
AppleScript won't know what file you're talking about.
I would agree with Paul that it is still less cumbersome to call a
handler,
but Paul, remember that the OP wanted to attach this action to some
FileMaker button. That implies that the script would be inside a
FileMaker
Script step, "Perform AppleScript".
If that is what the OP wanted, then that context is always inside an
imposed
(and invisible) tell block, so AS inside a FM script step that
collides with
FM dictionary entries will be problematic, or at least require "some
cumber"
in the process.
But, Diane (OP), you may wish to take Paul's advice anyway, and just
include
inside the handler a specific application tell statement.
on writeToFile(someText,f)
tell app "System Events" -- or whatever, as appropriate
...
end
end
The problem with OSAX is that they don't answer to an application. They
are at the bottom of the food chain, they get what ever falls out of
the trough. If the application hasn't defined "write" then you can use
"write" unambiguously. FMPro has defined "write" so you need to use raw
codes.
Once you know what's happening, it's easy to use the raw codes. In
fact, I use Smile and have the code at the top of the WorkSheet for cut
and pasting.
Gary also suggested saving the code as a separate application. This is
an excellent method but it has drawbacks. It takes time for the
application to launch, more time than the job takes for most things.
The alternative is stay-open applications, that run all the time so
they are ready when you want them. You have to ensure that people don't
quit the stand-alone, otherwise there the time lag again. The method I
used was to call libraries. The script is still running in FMP context
so it's necessary to use raw codes for write in the library scripts but
it is easy to call in to FMP then call functions from the library and
there is no time lag.
tell current record to set {currFile, currText} to {cell "file name",
cell "first name"}
set fmpXtra to load script file "xyz"
fmpXtra's writeToFile(currFile, currText)
Malcolm
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden