On Sep 15, 2011, at 03:34, Thomas Falk wrote:
> Yes, a shortcut would be nice, which places a new file directly where the 
> marker is in the project window. That would be very fine.

______________________________________________________________________

Hey Thomas,

I'm guessing you mean where the currently visible file is - yes?

In that case try the attached script.

I agree with you; the process of creating a new file in a project seems overly 
difficult.

--
Best Regards,
Chris

------------------------------------------------------------------------------------------------
# MAIN
------------------------------------------------------------------------------------------------
try
  set fileExtension to ""
  tell application "BBEdit"
    if name of front window ends with ".bbprojectd" then
      tell front text document
        set docFile to its file as alias
      end tell
      set cmd to "perl -wlne 'if (m/(?i)(\\..{3,4}$)/) {print \"$1\"}' <<< " & ¬
        quoted form of (docFile as text)
      set fileExtension to do shell script cmd
      tell me to set newFileName to text returned of (display dialog ¬
        "ENTER NAME FOR NEW FILE:" default answer fileExtension giving up after 
30)
      set newFilePath to my getParentFolder(docFile) & newFileName
    else
      error "FRONT WINDOW IS NOT A PROJECT DOCUMENT!"
    end if
  end tell
  tell application "Finder"
    set existsFlag to newFilePath exists
    if existsFlag = true then error "FILE ALREADY EXISTS!"
    do shell script "touch " & quoted form of (POSIX path of newFilePath)
    delay 0.05
    open newFilePath using application file id "com.barebones.bbedit"
  end tell
on error errMsg number errNum
  if errNum ≠ -128 then
    set {cr, sep} to {return, "------------------------------------------"}
    set e to sep & cr & "Error: " & errMsg & cr & sep & cr & "Error Number: " & 
errNum & cr & sep
    beep
    display dialog e
  end if
end try
------------------------------------------------------------------------------------------------
# » getParentFolder() : GET PARENT FOLDER OF AN ALIAS               MODIFIED 
2011-09-16 : 14:15
------------------------------------------------------------------------------------------------
on getParentFolder(fileAlias)
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item 
delimiters, ":"}
  set parentFolder to ((text items 1 thru -2 of (fileAlias as text)) as text) & 
":"
  set AppleScript's text item delimiters to oldTIDS
  return parentFolder
end getParentFolder
------------------------------------------------------------------------------------------------

-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to