How to Create New File in Selected Folder Using LaunchBar?
-
28-09-2020 - |
Question
Using Launchbar, I'd like to be able to do the following:
Navigate around by normal means in Launchbar > Once I'm in desired folder, I'd like to be able to run a command/action that asks me to enter a filename and then the command proceeds to ´touch´ (filename) in that directory.
How can this be achieved, any existing solutions?
Solution
This can be done by using the "New Text Document Here" action
Select folder -> tab -> start typing "New" -> select "New Text Document Here" -> type name -> enter.
If you're looking for a more complete solution that can create any type of file (including ones without the .txt extension that the New Text Document action forces) try this Applescript. Just put it in a file named New File.applescript
in the ~/Library/Application Support/LaunchBar/Actions/
directory:
on handle_string(dir)
display dialog "Enter filename:" default answer ""
set fname to text returned of result
set fullpath to dir & fname
try
do shell script "touch '" & fullpath & "'"
open location "x-launchbar:select?file=" & fullpath
on error errMsg
display dialog "Error: " & errMsg
open location "x-launchbar:hide"
end try
end handle_string
It'll touch the file, then select it in LaunchBar upon completion (you can comment out the line that does that by adding --
to the beginning of the line or just removing it).
OTHER TIPS
A custom script as in Justin's answer is the way to go if you need this to be Terminal-free, but if not I'd do it this way:
- Select folder via LaunchBar
- cmd-T (open Terminal there)
- Type "touch whateverfile", return
- cmd-W (close Terminal window)
- Invoke LaunchBar, cmd-R, return (to get back to the app you were in)