On Jan 22, 2017, at 15:59, Greg Raven <[email protected] <mailto:[email protected]>> wrote: > When opening one of my website projects, I would like BBEdit automatically to > open CodeKit, Github Desktop, and Transmit. I've tried a couple approaches, > but no joy so far.
Hey Greg, See “Document attachment points” and “Using Attachment Scripts” in the BBEdit manual. See also this post by yours truly: https://groups.google.com/d/msg/bbedit/EAM5uhEvCcc/ZZvb5GC8AgAJ <https://groups.google.com/d/msg/bbedit/EAM5uhEvCcc/ZZvb5GC8AgAJ> I've posted about attachment scripts before, so you might be able to find even more material. I haven't fooled with a “documentDidOpen” script for a while, and I must warn you that when I initially experimented with attachment scripts it was quite a chore getting them to work properly. Oh, well. In for a penny... Here you go: Script name MUST be: Document.documentDidOpen.scpt Script path MUST be: ~/Library/Application Support/BBEdit/Attachment Scripts/Document.documentDidOpen.scpt The internals of the script are reasonably self-explanatory or documented. Change projectFileAlias to correctly point to your project file (note it's an alias – do NOT use a POSIX Path). Change the items listed in variable appList to alter what apps are launched. ------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2017/01/22 23:00 # dMod: 2017/01/23 00:56 # Appl: BBEdit # Task: Attachment script using “documentDidOpen” event – launches apps if opened doc matches criteria. # Libs: None # Osax: None # Tags: @Applescript, @Script, @Attachment, @documentDidOpen, @Event, @Launches, @Apps ------------------------------------------------------------------------------------------- using terms from application "BBEdit" # Attachment handler for “documentDidOpen” event: on documentDidOpen(openedDocument) # Alias of project file we want to check for: set projectFileAlias to alias ((path to documents folder as text) & "BBEdit Projects:INFO-PROJECT.bbprojectd:") # List of application names we want to launch if opened document matches “fileAlias”: set appList to {"CodeKit", "Github Desktop", "Transmit"} # Filter to prevent script from running twice. if class of openedDocument = project document and name of openedDocument's window ends with "bbprojectd" then set openedDocumentAlias to file of openedDocument as alias if openedDocumentAlias = projectFileAlias then launchApps(appList) of me end if end if end documentDidOpen end using terms from # launchApps() handler on launchApps(appList) repeat with appName in appList tell application appName to run end repeat end launchApps on logText(theText) tell application "BBEdit" set logDoc to a reference to document id (ID of document "TEST_LOG.txt") tell logDoc set after its text to theText & linefeed end tell end tell end logText ------------------------------------------------------------------------------------------- Getting this to work properly was quite pesky, because the attachment mechanism doesn't support external debugging with Script Debugger. -- Take Care, Chris -- This is the BBEdit Talk public discussion group. 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> --- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/bbedit.
