Create text file in selected folder?

General discussions about LaunchBar
vcaston
Rank 1
Rank 1
Posts: 20
Joined: Thu Dec 01, 2011 8:41 pm

Create text file in selected folder?

Postby vcaston » Sun Apr 15, 2012 12:27 pm

Is there a way to create a new text file in a selected folder?

I searched the forums and help, but couldn't find anything.

In Quicksilver, I used to be able to select a folder and create a new file in it (could be text or from any other app, once you'd set up a template); then you could select the file to rename it; then you could open it and start typing. Used it all the time.

Victor

manfred
Objective Development
Objective Development
Posts: 562
Joined: Sat Jul 31, 2010 9:47 am
Location: Vienna
Contact:

Re: Create text file in selected folder?

Postby manfred » Wed Apr 18, 2012 11:01 am

If you create a template folder anywhere on your disk and place templates in it, it is easy to create an AppleScript / Shell script to copy the files into chosen directory.

For example:
  • Create a Template Directory anywhere on your disk
  • Use applications of your choice and create template files in this directory
  • Open your Apple Script Editor (located at /Applications/Utilities/)
  • Copy and paste the attached script into a new window and adjust values of templatePath as well as templateFileName
  • Save the script as .scpt file to the following directory: ~/Library/Application Support/LaunchBar/Actions
    e.g. »New TextEdit File.scpt«
  • Repeat this steps for all template files

Usage example:
  • Select any folder in LaunchBar
  • Press TAB and select your newly created action – the action copies the template to your selected folder and selects it in LaunchBar
  • Press cmd+R to rename the file
  • Press return to open it


Code: Select all

on open (_parameter)
   -- adjustment necessary
   
   set _templatePath to POSIX path of "/Path/To/Your/Templates/" -- path to your template directory e.g. /Users/manfred/Documents/Templates/
   set _templateFileName to "New File.rtf"
   
   -- ---------------------
   -- ---------------------
   
   set _destinationPath to (POSIX path of _parameter)
   
   try
      -- try to copy file
      do shell script "cp " & quoted form of (_templatePath & _templateFileName) & " " & quoted form of _destinationPath
      
      -- display selection only, if no error occured
      tell application "LaunchBar"
         set selection to (_destinationPath & _templateFileName)
         remain active
      end tell
      
   on error errMsg number errNum
      display dialog "Unable to copy file" with title "Error " & errNum with icon caution
   end try
end open

vcaston
Rank 1
Rank 1
Posts: 20
Joined: Thu Dec 01, 2011 8:41 pm

Re: Create text file in selected folder?

Postby vcaston » Sun Apr 19, 2015 12:43 am

I love this action. But the script doesn't seem to be working with LB 6.3. Does the script need to be modified?

Or is this something that has been superseded by a new feature?

Thanks.

norbert
Objective Development
Objective Development
Posts: 647
Joined: Thu Nov 09, 2006 6:30 pm

Re: Create text file in selected folder?

Postby norbert » Thu Apr 23, 2015 10:03 pm

LaunchBar comes with a built-in "New Text Document Here" action.

  • Select a folder in LaunchBar
  • Press Tab
  • Select the "New Text Document Here" action and hit Return

You will be asked for a filename. Once you hit Return the file is created an opened in your default text editor. The newly created file is also selected in LaunchBar, so you can apply further actions this file.

vcaston
Rank 1
Rank 1
Posts: 20
Joined: Thu Dec 01, 2011 8:41 pm

Re: Create text file in selected folder?

Postby vcaston » Thu Apr 23, 2015 10:19 pm

That's super, thanks.

The old script also allowed me to create new files from other programs, using template documents. Is that still possible?

Thanks.

best,

Victor


Return to “LaunchBar General”

Who is online

Users browsing this forum: No registered users and 2 guests