Opening other apps when opening a project

49 views
Skip to first unread message

Greg Raven

unread,
Jan 22, 2017, 4:59:10 PM1/22/17
to BBEdit Talk
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.

Has anyone else mastered this task?

Vlad Ghitulescu

unread,
Jan 22, 2017, 5:00:02 PM1/22/17
to BBEdit Talk

Yes, with Keyboard Maestro.

On 22 Jan 2017, at 22:59, Greg Raven 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.

Has anyone else mastered this task?

--
This is the BBEdit Talk public discussion group. 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>
---
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 bbedit+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.

Greg Raven

unread,
Jan 22, 2017, 5:04:23 PM1/22/17
to BBEdit Talk
Thanks for the suggestion. I already have a bash file that appears in my Scripts menu, which does the actual opening. I can quite get BBEdit to invoke it automatically when I open a web project, though.

Vlad Ghitulescu

unread,
Jan 22, 2017, 5:08:43 PM1/22/17
to BBEdit Talk

I've made a KBM-Macro that opens CodeKit, Tower and PathFinder (with a specific configuration) AND the BBEdit-project as well.

Christopher Stone

unread,
Jan 23, 2017, 2:08:20 AM1/23/17
to BBEdit-Talk
On Jan 22, 2017, at 15:59, Greg Raven <greg...@gmail.com> 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:


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

Greg Raven

unread,
Jan 23, 2017, 10:08:38 AM1/23/17
to BBEdit Talk, listm...@suddenlink.net
Chris,

Thanks for all of this.

I, too, have had difficulties getting attachment scripts to work, which is one reason why I was asking if anyone else had an approach to this. So far, I'm not able to get your script to work, but it might be a path issue.

I often open the first project of the day by double-clicking the .bbprojectd file in the Finder, so what I think I'll do for now is to create an AppleScript application that opens the .bbprojectd file (which will also open BBEdit, of course), and then open CodeKit, Github Desktop, and Transmit. It will be crude, but it should get me where I want to go.

Greg Raven

unread,
Jan 23, 2017, 10:38:22 AM1/23/17
to BBEdit Talk, listm...@suddenlink.net
This is what I came up with:

on run
-- open this project
tell application "BBEdit"
open "full:path:to:project.bbprojectd"
end tell
-- open CodeKit
tell application "CodeKit"
launch
end tell
-- open Github Desktop
tell application "Github Desktop"
launch
end tell
-- open Transmit
tell application "Transmit"
launch
end tell
end run

Christopher Stone

unread,
Jan 23, 2017, 8:48:16 PM1/23/17
to BBEdit-Talk
On Jan 23, 2017, at 09:38, Greg Raven <greg...@gmail.com> wrote:
This is what I came up with:


Hey Greg,

That'll work fine.

Here's what I'd do:

----------------------------------------------------------------------
# USER SETTINGS:
----------------------------------------------------------------------

# Relative-Path (tilde or $HOME-based path) if possible.
set projectPath to "~/Documents/BBEdit Projects/INFO-PROJECT.bbprojectd"

set appList to items 1 thru -2 of
   "GitHub Desktop", ¬
   "TextEdit", ¬
   "Transmit", ¬
   ""}

-- Written this way for easy additions, removals, and sorting.

----------------------------------------------------------------------

tell application "System Events" to set projectPath to POSIX path of disk item projectPath

repeat with theApp in appList
   tell application theApp
      if it is not running then run
   end tell
end repeat

tell application "BBEdit"
   if it is not running then -- This code works-around an “activate” bug in some versions of macOS.
      run
      delay 1
   end if
   activate
   open projectPath
end tell

----------------------------------------------------------------------

Rule-of-the-thumb – never use full paths if a relative path will work.

I generally use relative-aliases, but most people don't understand these as well as tilde-based paths (as I've used above).

An example of same:

set projectAlias to alias ((path to documents folder as text) & "BBEdit Projects:INFO-PROJECT.bbprojectd:")

** “Relative-Alias” is a term I coined years ago and is not official Apple nomenclature.

Relative paths (and relative aliases) are portable.  Hard-coded full-paths are very often NOT portable.

System Events understands tilde-based paths (as seen in the script), but don't use any kind of POSIX Path in the Finder.  (While there are instances that work there are many more that don't, so it's better to stick with HFS paths and aliases when working in the Finder.)

--
Take Care,
Chris


Greg Raven

unread,
Jan 24, 2017, 7:28:55 AM1/24/17
to Bare Bones
Chris,

This works great. Thanks again!

Greg Raven
20258 US Hwy 18 Ste 430-513
Apple Valley, CA 92307-6197

--
This is the BBEdit Talk public discussion group. 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>
---
You received this message because you are subscribed to a topic in the Google Groups "BBEdit Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bbedit/UFGNIhlvgKE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bbedit+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages