Re: AppleScript Open File in BBEdit 9.6

358 views
Skip to first unread message

Robert Huttinger

unread,
Jun 22, 2011, 3:15:49 PM6/22/11
to bbe...@googlegroups.com
it may be a permissions issue, try setting permission to 755 or 777 and try again


bo huttinger


On Wed, Jun 22, 2011 at 3:04 PM, Rich F <bee...@gmail.com> wrote:
Hi folks.

For the life of me I can't find a way of opening a file in a
subdirectory in my webserver directory.


set myF to file "/Library/WebServer/Documents/alpha/bravo/items.lasso"

tell application "BBEdit 9.6"
       open myF as alias
end tell

It says can't get the file.  I know it's there.  I've tried how to
change the syntax on the open and I just can't get it.  Any ideas?

Cheers

--
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 bbe...@googlegroups.com
To unsubscribe from this group, send email to
bbedit+un...@googlegroups.com
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 "sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Patrick Woolsey

unread,
Jun 22, 2011, 3:25:05 PM6/22/11
to bbe...@googlegroups.com
Rich F <bee...@gmail.com> sez:

>For the life of me I can't find a way of opening a file in a
>subdirectory in my webserver directory.
>
>set myF to file "/Library/WebServer/Documents/alpha/bravo/items.lasso"
>
>tell application "BBEdit 9.6"
> open myF as alias
>end tell
>
>It says can't get the file. I know it's there. I've tried how to
>change the syntax on the open and I just can't get it. Any ideas?


The path format doesn't match; assuming you want to use Unix paths:

====
set myF to POSIX file "/Users/pwoolsey/Desktop/foo.txt"

tell application "BBEdit"
open myF
end tell
====


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com>
P.O. Box 1048, Bedford, MA 01730-1048

BeeRich

unread,
Jun 22, 2011, 3:30:51 PM6/22/11
to bbe...@googlegroups.com
Hi Patrick.

That resulted in a "doesn't understand the open message". If I want to avoid the POSIX syntax, do I use colons? Still didn't work.

Robert Huttinger

unread,
Jun 22, 2011, 3:33:59 PM6/22/11
to bbe...@googlegroups.com
there are 2 kinds of paths you can use you may want to do a search and get the syntax right. this is a little tricky on its face...

bo huttinger

BeeRich

unread,
Jun 22, 2011, 3:56:45 PM6/22/11
to bbe...@googlegroups.com
I tried recording it, but she wouldn't give me any syntax.

Tried colons, didn't work.

Cheers


On 2011-06-22, at 3:12 PM, Lorin Rivers wrote:

> Glen,
>
> In all my scripts that open files, I use this structure instead:
> open {file "infernal:private:etc:apache2:httpd.conf"}
>
> Which is what AppleScript emits if you record BBEdit opening a file.
>
> HTH!

BeeRich

unread,
Jun 22, 2011, 4:01:57 PM6/22/11
to bbe...@googlegroups.com
But then I can't initiate it from FileMaker. That's the whole point of this. If I was in BBEdit originally then I could just click on a Text Factory. I need FMP to launch that TF, but only after the file has been opened.


On 2011-06-22, at 3:58 PM, Doug McNutt wrote:

> I'm biased but the sooner one gets out of Applescript the better UNIX works.
>
> Install the bbedit tool from Bare bones
>
> do shell script "bbedit " & quoted form of "/Library/WebServer/Documents/alpha/bravo/items.lasso"

Robert Huttinger

unread,
Jun 22, 2011, 4:04:49 PM6/22/11
to bbe...@googlegroups.com
this is like asking peter to punch paul for you but, if you open automator and your start a 'watch me do' session and select a folder, then stop. when finished you will have a list of items in the watch me do section. drag the 'select folder' (or similar) below the watch me do action and it will create a new action with the actual applescript in it!

did that make any sense?

bo


--

BeeRich

unread,
Jun 22, 2011, 4:20:59 PM6/22/11
to bbe...@googlegroups.com
Yes. I didn't know you were using Automator. I was trying to record in the AE window.

BeeRich

unread,
Jun 22, 2011, 4:22:34 PM6/22/11
to bbe...@googlegroups.com
Actually, while we are on topic, how do I select a text factory for the open file?

As an option, I'm trying to use AppleScript syntax for a single replace and save. This is what I have for the replace, and she's not compiling:

replace "\x0B" using "\r" searching in selection of text window 1 options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}

Any ideas? That is a gremlin inserted by our lovely FileMaker.

Cheers


On 2011-06-22, at 4:04 PM, Robert Huttinger wrote:

Robert Huttinger

unread,
Jun 22, 2011, 4:23:32 PM6/22/11
to bbe...@googlegroups.com
Sorry, yes I know :) I was trying to give you a local option of
viewing the exact syntax you were looking for but my way is
confusing...

Sent from my iPhone

BeeRich

unread,
Jun 22, 2011, 4:26:13 PM6/22/11
to bbe...@googlegroups.com
Hey no apologies required. That's a great tool. I should use that in the future.

Patrick Woolsey

unread,
Jun 22, 2011, 5:30:56 PM6/22/11
to bbe...@googlegroups.com
BeeRich <bee...@gmail.com> sez:

>That resulted in a "doesn't understand the open message".

Should work; what was the exact text of your script? (and, did you replace
my example path with a valid path? :)


>If I want to avoid the POSIX syntax, do I use colons?

Yes; in that case you should write the path in traditional AppleScript
fashion and use 'alias', like this:

===
set myF to alias "Hard Drive:Users:pwoolsey:Desktop:foo.txt"
...

BeeRich

unread,
Jun 22, 2011, 3:39:24 PM6/22/11
to bbe...@googlegroups.com
(not sure if this went through)

OK, got it to work:

open myF as alias

Any clarification on the POSIX notation?

Thanks Patrick!


On 2011-06-22, at 3:25 PM, Patrick Woolsey wrote:

Christopher Stone

unread,
Jun 22, 2011, 6:16:52 PM6/22/11
to bbe...@googlegroups.com
On Jun 22, 2011, at 14:04, Rich F wrote:
> For the life of me I can't find a way of opening a file in a subdirectory in my webserver directory...

> set myF to file "/Library/WebServer/Documents/alpha/bravo/items.lasso"
______________________________________________________________________

Hey Rich,

It's been mentioned that you're using the wrong syntax there to reference a file 'as alias'.

Note that BBEdit will deal with a posix path without conversion to a posix file or alias:

----------------------------------------------------------------------
set posixFileRef to "/Users/chris/test_directory/test.txt"

tell application "BBEdit"
open posixFileRef
end tell
----------------------------------------------------------------------

In the Finder I run this script with FastScripts using 'Control-P' to put alias-formatted references of the selected items on the clipboard:

----------------------------------------------------------------------
# Author: ccs
# Created: 12-29-2010 : 18:48:00
# Modified: 01-05-2011 : 02:15:00
# Application: Finder
# Purpose: Copy Alias reference of selected items to the Clipboard.
# Dependencies: none
----------------------------------------------------------------------
tell application "Finder"
try
set sel to selection as alias list
if length of sel > 0 then
set beginning of sel to ""
set end of sel to ""
set AppleScript's text item delimiters to {"\"" & return & "alias " & "\""}
set sel to sel as string
set sel to paragraphs 2 thru -2 of sel
set AppleScript's text item delimiters to return
set sel to sel as string
set the clipboard to sel
end if
on error errMsg number errNum
beep
display dialog "Error: " & errMsg & return & "Error Number: " & errNum
end try
end tell
----------------------------------------------------------------------

I find that automating this task leads to fewer mistakes and "Doh!' moments. :)

Here's a similar script for Posix paths:

----------------------------------------------------------------------
# Author: ccs
# Created: 2010-10-06 : 06:43
# Modified: 2011-06-22 : 17:00
# Application: Finder
# Purpose: Get posix path of selected items and copy to clipboard
# Dependencies: none
----------------------------------------------------------------------
tell application "Finder"
try
if (count of windows) > 0 then
set sel to selection as alias list
if length of sel > 0 then
repeat with ndx in sel
set ndx's contents to "\"" & (POSIX path of ndx) & "\""
end repeat
set AppleScript's text item delimiters to linefeed
set sel to sel as string
set the clipboard to sel
end if
end if
on error errMsg number errNum
beep
display dialog "Error: " & errMsg & return & "Error Number: " & errNum
end try
end tell
----------------------------------------------------------------------

--
Best Regards,
Chris

BeeRich

unread,
Jun 22, 2011, 3:28:55 PM6/22/11
to bbe...@googlegroups.com
Hi Bo. Thanks for the reply.

Unfortunately that didn't work either on 777.

Lorin Rivers

unread,
Jun 22, 2011, 3:12:25 PM6/22/11
to bbe...@googlegroups.com

On Jun 22, 2011, at 14:04 , Rich F wrote:

> Hi folks.


>
> For the life of me I can't find a way of opening a file in a
> subdirectory in my webserver directory.
>
>

> set myF to file "/Library/WebServer/Documents/alpha/bravo/items.lasso"
>

> tell application "BBEdit 9.6"
> open myF as alias
> end tell
>
> It says can't get the file. I know it's there. I've tried how to
> change the syntax on the open and I just can't get it. Any ideas?
>

> Cheers


Glen,

In all my scripts that open files, I use this structure instead:
open {file "infernal:private:etc:apache2:httpd.conf"}

Which is what AppleScript emits if you record BBEdit opening a file.

HTH!

--
Lorin Rivers
Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
<mailto:lri...@mosasaur.com>
512/203.3198 (m)


BeeRich

unread,
Jun 22, 2011, 3:34:18 PM6/22/11
to bbe...@googlegroups.com
OK, got it to work:

open myF as alias

Any clarification on the POSIX notation?

Thanks Patrick!


On 2011-06-22, at 3:25 PM, Patrick Woolsey wrote:

Doug McNutt

unread,
Jun 22, 2011, 3:58:06 PM6/22/11
to bbe...@googlegroups.com
At 12:04 -0700 6/22/11, Rich F wrote:
>For the life of me I can't find a way of opening a file in a
>subdirectory in my webserver directory.
>
>
>set myF to file "/Library/WebServer/Documents/alpha/bravo/items.lasso"
>
>tell application "BBEdit 9.6"
> open myF as alias
>end tell
>

I'm biased but the sooner one gets out of Applescript the better UNIX works.

Install the bbedit tool from Bare bones

do shell script "bbedit " & quoted form of "/Library/WebServer/Documents/alpha/bravo/items.lasso"

--

--> A fair tax is one that you pay but I don't <--

BeeRich

unread,
Jun 22, 2011, 11:05:52 PM6/22/11
to bbe...@googlegroups.com
Hi Chris. Got it to work with colons and an alias in there.

Cheers

BeeRich

unread,
Jun 22, 2011, 11:08:35 PM6/22/11
to bbe...@googlegroups.com
Sorry Patrick. I got this to work.

How can I then launch a Text Factory on that file? I can't seem to find anything in the dictionary.

Rich F

unread,
Jun 22, 2011, 3:04:39 PM6/22/11
to BBEdit Talk
Hi folks.

For the life of me I can't find a way of opening a file in a
subdirectory in my webserver directory.


set myF to file "/Library/WebServer/Documents/alpha/bravo/items.lasso"

tell application "BBEdit 9.6"
open myF as alias
end tell

Walter Ian Kaye

unread,
Jun 23, 2011, 7:51:30 AM6/23/11
to bbe...@googlegroups.com
BTW, an easy way to get an alias filepath is just run this in Script Editor:

choose file

Then navigate to and "open" the file, and copy the result. :-)

-boo


At 11:08 p -0400 06/22/2011, BeeRich didst inscribe upon an electronic papyrus:

BeeRich

unread,
Jun 23, 2011, 8:48:01 AM6/23/11
to bbe...@googlegroups.com
You can also drag the file into the AE window and the path to the file comes up.

Christopher Stone

unread,
Jun 23, 2011, 3:04:25 PM6/23/11
to bbe...@googlegroups.com
On Jun 23, 2011, at 06:51, Walter Ian Kaye wrote:
> BTW, an easy way to get an alias filepath is just run this in Script Editor:
>
> choose file

______________________________________________________________________

That can be handy, but it's also a bit limiting due to its restriction to files. Folders are not allowed.

More versatile is:

choose file with multiple selections allowed

or

choose folder with multiple selections allowed

Unless you really do want only one specific item.

I never use these unless I require user interaction in a script. The scripts I posted yesterday do the job for me, and just in case I have the following script available via a few keystrokes from Typinator:

tell application "Finder"


set sel to selection as alias list

end tell

In general I'd much rather navigate around the Finder itself rather than through a dialog.

--
Best Regards,
Chris

Walter Ian Kaye

unread,
Jun 24, 2011, 10:22:46 AM6/24/11
to bbe...@googlegroups.com
Oh, that must be a new feature; doesn't work in my old SE 1.9.


At 08:48 a -0400 06/23/2011, BeeRich didst inscribe upon an electronic papyrus:

Reply all
Reply to author
Forward
0 new messages