This hasn't posted to the list in more than 2 hours, so I'm sending again.
______________________________________________________________________
Hey TJ,
On Jul 02, 2011, at 15:33, TJ Luoma wrote:
> Problem: I want to open the front-most file in BBEdit in another application
> by pressing some keyboard command.
>
> Let's say the other application is TextEdit, but it could be any application.
Simple. (See script below.)
> do shell script "open -e " & thepath
>
> But I always get an error such as this:
>
> "BBEdit got an error: Can't make POSIX path of text document into type POSIX
> path of text document 1."
Let's start by fixing your script:
------------------------------------------------------------------------------------------------
tell application "BBEdit"
set thefile to document 1 of application "BBEdit"
set thepath to file of thefile --> returns an alias
set thepath to POSIX path of thepath --> properly coerce alias to posix path
end tell
# Since Mac paths can contain spaces and characters that Posix doesn't like we
quote the string:
set thepath to quoted form of thepath
do shell script "open -e " & thepath
------------------------------------------------------------------------------------------------
Now let's do it with pure Applescript and provide some error checking:
------------------------------------------------------------------------------------------------
try
tell application "BBEdit"
if front window exists then
if class of front window is not in {shell window, scratchpad_window} then
tell front text document of front window
if its file ≠ missing value then
set frontTextDoc to its file as alias
else
error "The Front Text Document Is Unsaved!"
end if
end tell
else
error "Front Window Is NOT A Text Document!"
end if
else
error "No Windows Are Open!"
end if
end tell
tell application "TextEdit"
activate
open frontTextDoc
end tell
on error errMsg number errNum
set sep to "=============================="
set e to sep & return & "Error: " & errMsg & return & sep & return ¬
& "Error Number: " & errNum & return & sep
beep
display dialog e
end try
------------------------------------------------------------------------------------------------
For my own use I usually won't put in so much error checking and will just let
the generic error-handler catch whatever comes up.
Hmm. A good beginner book...
Let's start out with some freebies:
The Applescript Language Guide:
http://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html
http://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf
Old but worth having:
AppleScript Finder Guide - January 05, 1994:
http://manuals.info.apple.com/en_US/AppleScriptFinderGuide.pdf
AppleScript Scripting Additions Guide - January 05, 1996:
http://manuals.info.apple.com/en_US/0305098AASADDGENG.pdf
Applescript For Absolute Starters v1.4:
http://files.macscripter.net/sourcebook/AS4ASb2.pdf
--
The Applescript Users List (must join and lurk and ask questions):
http://lists.apple.com/mailman/listinfo/applescript-users
MacScripter:
http://macscripter.net/
--
Books I own:
"Learn Applescript: The Comprehensive Guide to Scripting and Automation on Mac
OS X 3rd Edition" by Hamish Sanderson & Hanaan Rosenthol
"Applescript: The Definitive Guide 2nd Edition" by Matt Neuburg
"Applescript: Developer Reference" by Mark Conway Munro
If you only buy one I'd probably recommend the first one by Hamish and Hanaan.
I'm also interested in:
"Apple Training Series: AppleScript 1-2-3" by Sal Soghoian & Bill Cheeseman
I'm interested in this one because Bill is involved, and I've known him online
for about 17 years.
Now then - I'll bet you got more than you bargained for. :)
Drop me a line if you have any questions.
--
Best Regards,
Chris
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>