Open BBEdit image dialog with AppleScript

52 views
Skip to first unread message

jgill

unread,
Jun 3, 2014, 5:11:35 AM6/3/14
to bbe...@googlegroups.com
I wish that the BBEdit AppleScript Dictionary gave syntax examples!

In a web page building script, I can do everything I want except for inserting images.

Ideally, I would like to invoke the BBEdit 'Images' dialog and return the file path, alt, and dimensions to my script.

When I try to record the actions with Script Debugger, it does nothing.

Is this possible?

Christopher Stone

unread,
Jun 3, 2014, 4:38:15 PM6/3/14
to BBEdit-Talk
On Jun 03, 2014, at 04:11, jgill <joegille...@gmail.com> wrote:
I wish that the BBEdit AppleScript Dictionary gave syntax examples!
______________________________________________________________________

Hey Joe,

You've just given voice to one of the major frustrations of everyone who's attempted to learn AppleScript.

:D

That's why we have a BBEdit user list, an Applescript Users List, and MacScripter.net.

Ideally, I would like to invoke the BBEdit 'Images' dialog and return the file path, alt, and dimensions to my script.

Can't.

Search the dictionary for image.  You won't find much.

You can roll-your-own by doing something similar to this:

-------------------------------------------------------------------------------------------
set imgList to choose file with prompt ¬
  "Choose 1 or More Images:" of type {"bmp", "gif", "jpg"} ¬
  default location (path to desktop) ¬
  with multiple selections allowed

set AppleScript's text item delimiters to (character id 0)

repeat with i in imgList
  set _record to do shell script "mdls -raw -nullMarker None -name kMDItemFSName -name kMDItemPixelWidth -name kMDItemPixelHeight " & ¬
    quoted form of (POSIX path of i)
  set {_name, _width, _height} to (text items of _record)
end repeat
-------------------------------------------------------------------------------------------

Put it together the way you want and insert it in your document where you want.

There is more data available from 'mdls' of course, and you could always download and install 'exiftool' if you want the 700lb gorilla of image-info-tools.

--
Best Regards,
Chris

jgill

unread,
Jun 4, 2014, 10:26:17 AM6/4/14
to bbe...@googlegroups.com
Christopher comes to the rescue again ;?) I am not familiar with shell scripts so I would never have come up with this solution myself. I have played around with this and found how to derive the relative path that I need for an image tag. The alt and title attributes can be added with a second dialog.

My 'solution' was to invoke the BBEdit image dialog with a simulated keypress (ctrl/cmd/i) and that inserts the correct markup in the correct place but there doesn't seem to be any way to detect when this process has finished so I can continue with the next bit.

My page building script inserts placeholders *image* and then I replace those with the generated <img.. tag.

Thanks again, Christopher

Christopher Stone

unread,
Jun 4, 2014, 9:33:18 PM6/4/14
to BBEdit-Talk
On Jun 04, 2014, at 09:26, jgill <joegille...@gmail.com> wrote:
but there doesn't seem to be any way to detect when this process has finished so I can continue with the next bit.
______________________________________________________________________

Hey Joe,

Exactly.

If you want to actually drive the User-Interface then something like Keyboard Maestro is usually the way to go.  Amongst other things you can build fairly complex dialogs with it.

AppleScript is not designed to wait for user-interaction outside of its own UI-elements.

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages