Request for "Shelf"

General discussions about LaunchBar
ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Request for "Shelf"

Post by ptujec » Thu Aug 13, 2009 5:18 pm

I adapted the script a little bit so that it would also work in case you accidently hit return instead of spacebar ;)

Update: You can also apply this hint to do the trick. viewtopic.php?p=13866#p13866

Code: Select all

-- http://forums.obdev.at/viewtopic.php?t=2014
-- adapted by ptujec 13/08/09
------------------------------------------

on handle_string(theString)
   set input to newClipping(theString)
end handle_string

---

on run
   tell me to activate
   set theString to text returned of (display dialog "Enter new Text Clip" with title "New Text Clip" default answer "" buttons {"Cancel", "Create"} default button 2)
   set input to newClipping(theString)
end run

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

on newClipping(input)
   if input is not "" then
      -- added the next line to make it work when LB is in nonactivating mode (by @ptujec)
      tell me to activate

      -- Create a folder "Shelf" first and also relpace "YOUR USERNAME" in the following line
      set clipFolder to POSIX file "/Users/YOUR USERNAME/Library/Application Support/LaunchBar/Shelf/" as string
      
      set clipName to text returned of (display dialog "Enter name for new Text Clip containing" & return & quoted form of input with title "New Text Clip" default answer "" buttons {"Cancel", "Create"} default button 2)
      
      set clipFile to clipFolder & clipName & ".clip.txt"
      
      try
         set open_file to open for access file clipFile with write permission
         -- erase current contents of file:
         set eof of open_file to 0
         write input as text to open_file starting at eof
         close access open_file
      on error
         try
            close access file clipFile
            display dialog "Error"
         end try
      end try
      open location "x-launchbar:hide"
   end if
end newClipping

Post Reply