Saturday, January 20, 2018
  • Index
  •  » Automator
  •  » Move to Trash after completion of Folder Action

#1 2013-04-24 02:24:13 am

Benedictine
Member
Registered: 2013-03-27
Posts: 8

Move to Trash after completion of Folder Action

I have set up an Automator folder workflow attached to a folder on my desktop which adds the contents to a specific 'group', (folder) in my DevonThink Pro Office database which, when the action is run, does just that but leaves the (presumed) original in the folder on the desktop. This is fine but as I do not want to keep the items in the desktop folder, (as they are now in my database) I have to manually drag them to the Trash. Is there a way in which I can automate this 'move to trash'?

I would attach a screenshot of my workflow but I don't know how to!

Thanks for any help.

Offline

 

#2 2013-04-25 03:18:44 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Move to Trash after completion of Folder Action

Hello.

You would end your Automator workflow with an applescript action which has the below inside, but with  a correct path.

Applescript:

tell application "Finder"
   delete every item of folder "Hfs:Path:To:Your:Folder:With:Items:To:delete:inside of it:"
end tell

If you have trouble getting the hfspath, then mark the folder with the items in it, and run the script below, then it should be put onto the clipboard, from where you can easily paste it into the AppleScript action.

Applescript:

property l : {"Posix", "Hfs", "Url", "Rtf"}
property d : l's item 1 -- from Kai's dialog demo
global choice
tell application "Finder" to set sel to selection
if sel ≠ {} then
   tell application "System Events"
       tell (first application whose frontmost is true)
           activate
           set choice to (choose from list l default items d with prompt "Insert File identifier" OK button name {"Ok"})
           if choice is false then error number -128
       end tell
   end tell
else
   beep 2
   return
end if

set the clipboard to ("\"" & makeListOf(choice, sel) & "\"")


on makeListOf(theWay, aliasList)
   set tids to AppleScript's text item delimiters
   
   set produced to {}
   set interrim to {}
   if theWay is {"Posix"} then
       repeat with anElm in aliasList
           set interrim to interrim & POSIX path of (anElm as alias)
           
       end repeat
       set AppleScript's text item delimiters to return
       set produced to interrim as Unicode text
   else if theWay is {"Hfs"} then
       repeat with anElm in aliasList
           set interrim to interrim & (anElm as alias)
       end repeat
       set AppleScript's text item delimiters to return
       set produced to interrim as Unicode text
   else if theWay is {"Url"} then -- thanks Stefan!
       repeat with anElm in aliasList
           tell application "Finder" to set interrim to interrim & URL of (anElm as alias)
       end repeat
       set AppleScript's text item delimiters to return
       set produced to interrim as Unicode text
   else if theWay is {"Rtf"} then
       if (count of aliasList) > 1 then
           display alert "Only one at a time."
       end if
       set interrim to rtfLink((item 1 of aliasList) as alias)
       set produced to interrim
   end if
   set AppleScript's text item delimiters to tids
   return produced
end makeListOf

on rtfLink(anAlias)
   -- totally stolen from [url]http://www.macosxhints.com/article.php?story=20091002090934432[/url]
   -- I have a shell file - rather compact, but I can't figure out where that leading zero comes from.
   -- I'll come back and revise this one as well.
   local _msglnk
   set _linkText to extract_shortname_from(extract_filename_from(anAlias as text)) as text
   tell application "Finder" to set _msglnk to URL of (anAlias as alias)
   set startEcho to "echo "
   set echoDelimiter to "'"
   
   set html_1 to "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">
<title>"

   set html_2 to "</title>
<meta name=\"Generator\" content=\"Cocoa HTML Writer\">
<meta name=\"CocoaVersion\" content=\"1038.11\">
<style type=\"text/css\">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
</style>
</head>
<body>
<p class=\"p1\"><a href=\""

   set html_3 to "\">"
   set html_4 to "</a></p>
</body>
</html>"

   
   set echoCommand to startEcho & echoDelimiter & html_1 & _linkText & html_2 & _msglnk & html_3 & _linkText & html_4 & echoDelimiter
   set textutilCommand to " | textutil -convert rtf -inputencoding UTF-8 -format html -stdin -stdout"
   set pbcopyCommand to " | pbcopy -Prefer rtf"
   
   set entireCommand to echoCommand & textutilCommand & pbcopyCommand
   
   do shell script entireCommand
   copy (the clipboard) to theResult
   return theResult
end rtfLink

-- AS SDK *tinkered* and *cloned*
on extract_shortname_from(the_filepath) -- clone of one from the SDK made by me.
   set the_filepath to the_filepath as text
   try
       set x to the offset of "." in (the reverse of every character of the_filepath) as string
   on error
       return the_filepath
   end try
   return ((characters 1 thru -(x + 1) of the_filepath) as text)
end extract_shortname_from

on extract_filename_from(the_filepath) -- slightly modified since HFS-name of rtfd document ends with ":"
   local x
   set the_filepath to the_filepath as text
   set x to the offset of ":" in (the reverse of every character of the_filepath) as string
   if x is 1 then
       set the_filepath to characters 1 thru -2 of the_filepath as text
       return extract_filename_from(the_filepath)
   end if
   return ((characters -(x - 1) thru -1 of the_filepath) as text)
end extract_filename_from

There should be a lot of scripts for taking a picture of the frontmost window, I thing command-shift-4 does it automatically, please look at a listing of keyboard shortcuts by google.

Or try the script I use below.

Applescript:

-- flat5 [url]http://macscripter.net/viewtopic.php?id=38482[/url]
tell application "System Events" -- get frontmost process
   set frontmostProcess to first process where it is frontmost -- this will be the script process
   set visible of frontmostProcess to false -- hide the script process
   repeat while (frontmostProcess is frontmost) -- wait until the script is hided
       delay 0.2
   end repeat
   set secondFrontmost to name of first process where it is frontmost -- get name of frontmost process (ignoring the script process)
   set frontmost of frontmostProcess to true -- unhide the script process
end tell
tell application secondFrontmost to set winID to id of window 1 -- get WindowID of frontmost window of frontmost process
do shell script "screencapture -c -x -w "
--" & winID

-- -c is used to store it in the clipboard. -x is used to mute the sound. -l is used to refer to the prefered windowid.

The scripts are meant to be run from the Script menu, but I think they'll work from Quicksilver as well, if they reisde in a folder scanned by Quicksilver.

Last edited by McUsrII (2013-04-25 05:12:18 am)


Filed under: Automator

Offline

 

#3 2013-04-25 07:25:54 am

Benedictine
Member
Registered: 2013-03-27
Posts: 8

Re: Move to Trash after completion of Folder Action

thank you for your excellent help McUsrII, this does exactly what I want. Cheers.:)

Offline

 

#4 2013-04-25 03:11:35 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: Move to Trash after completion of Folder Action

Hello.

I am glad I could help, you'd be amazed by what you can find if you started to search this fora, AppleScript and Mac Os X in particular, when it comes to AppleScript. smile

Offline

 
  • Index
  •  » Automator
  •  » Move to Trash after completion of Folder Action

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)