>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.
In that case, you'll use:
tell application "TextEdit"
open <foo>
end tell
>set thefile to document 1 of application "BBEdit"
A document has properties, one of which is its file -- documents
don't equate to files on disk, though. So, "<foo>" in the above becomes:
file of document 1 of application "BBEdit"
Thus:
tell application "TextEdit"
open file of document 1 of application "BBEdit"
end tell
>2. recommend a good "AppleScript for beginners" book?
<http://www.barebones.com/support/resources/bookshelf.html>
Enjoy,
R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>
Someday I'll look back on all this and laugh... until they
sedate me.
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:
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:
--
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
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