At 11:35 PM +0100 28/2/01, Sjoerd Op 't Land wrote:
>> Without the external collection, it may not be easy. I haven't tried
>> the above string with "send", but generally the Finder won't accept
>> text strings for file references, and Metacard can only send text
>> strings.
>I think I don't quite follow you, because I thought that when you send a
>"miscdosc" message, a script is executed. At least so acts MC. Doesn't
>"miscdosc" stand for "Miscellaneous: Do Script"?
I checked out some old mails on this issue. I rememeber trying to do
something similar a long time ago. I may have made a breakthrough
just now. :) (Be warned that a lot of this is based on a shaky
knowledge of Apple Events and AppleScript.)
The "miscdosc" is the id of the Apple Event you are sending. The
"miscdosc" event is handled by Metacard, so you can use this when
sending events to Metacard. However, "miscdosc" is not handled by all
programs.
As an example, the id for the beep command that is contained in the
Standard Additions scipting additions (in the System Folder) is
"sysobeep". The following simple example should produce 2 beeps.
Example 1
on mouseUp
send "2" to program "Finder" with "sysobeep"
end mouseUp
Sending the message to the Finder is only done as a convenience, I
guess, because it's always running. The Finder doesn't handle this
Apple Event itself (I think), but as Scripting Addition commands can
be called anywhere (as a kind of basic command) it eventually gets
handled.
Using the same logic, I thought I could send a "sysodsct" event to
the Finder that would run a simple AppleScript. This event is also
listed in the Standard Additions file, and is meant to run a
specified AppleScript. The one-line script I wanted to run was
something like this:
tell application "Finder" to open file <someFile>
This should open the specified file with its associated application.
When I tried the following example a couple of years ago, it didn't work:
Example 2
on mouseUp
answer file "" ##select a PDF file for example
if it is not empty then
put it into tFile
## change to Mac style file syntax
replace "/" with ":" in tFile
if char 1 of tFile is ":" then delete char 1 of tFile
runScriptOpenDoc tFile
end if
end mouseUp
on runScriptOpenDoc pDocName
put "tell application " & quote & "Finder" & quote & " to open file " \
& quote & pDocName & quote into tScript
send tScript to program "Finder" with "sysodsct"
end runScriptOpenDoc
BUT, this morning I tried it, and it worked. Magic! Either something
changed with the Finder/Mac OS (I've been through a couple of OS
upgrades since then, now using 9.0.4) or something has changed in
Metacard. (Any secrets you're not telling us, Scott?)
I've not experimented to see what other AppleScripts you can run in
this way. I also don't know if you can run AppleScipts greater than
one line. However, looking at the aete resource in ResEdit it
mentions that the "sysodsct" can also be used to run an AppleScript
file.
Sjoerd, you still may be thinking this a roundabout way to do this.
Instead of running an AppleScript fragment, why not just send an
AppleEvent that the Finder handles itself? After all, the Finder
handles enough events to let you do almost anything relating to file
management on your Mac. The problem is that most Finder Apple Events
require file references to be of a particular "type". A simple string
such as "Mac HD:My Folder:Myfile.pdf" won't work. You may have
encountered this problem in AppleScript when dealing with the Finder.
Often you have to precede file references with the word "file" or
"alias" to get things to work, but it's not always clear which one
to use or when to use it. (I usually steal AppleScripts from others,
and gave up wondering why they work or don't work a long time ago.)
However, I'm now encouraged to experiment a little further with the
"sysodsct" approach, and see how this might be exploited.
Cheers
Dave Cragg
Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.