Siriusic

Q: How to create a toggle with Automator

Greetings,

I am attempting to create a runnable if/then script with Automator or Apple Scripts. I have minimal experience with Apple Scripts, so I do not know if this is even possible. I need the script to check if a particular folder has any content, and depending on the result, run one of two Automator scripts I have created.


If possible, I would love to have a toggle instead, simply switching off between my two Automator scripts.

Any help is much appreciated.

MacBook Pro with Retina display, OS X El Capitan (10.11.5), null

Posted on Jun 11, 2016 12:02 PM

Close

Q: How to create a toggle with Automator

  • All replies
  • Helpful answers

  • by VikingOSX,Solvedanswer

    VikingOSX VikingOSX Jun 11, 2016 1:21 PM in response to Siriusic
    Level 7 (20,819 points)
    Mac OS X
    Jun 11, 2016 1:21 PM in response to Siriusic

    Here is the basic flow to test if a specified folder is empty or otherwise. It calls automator once with the appropriate workflow.

     

    property folder_to_check : ((path to desktop) as text) & "Test:" as alias

    property workflow_for_items : ((path to home folder) as text) & "folder_has_items.workflow"

    property workflow_for_noitems : ((path to home folder) as text) & "folder_has_noitems.workflow"

     

    set qtdworkflow to ""

     

    tell application "Finder"

         if items of folder_to_check is {} then

             set qtdworkflow to workflow_for_noitems's POSIX path's quoted form

         else

             set qtdworkflow to workflow_for_items's POSIX path's quoted form

         end if

    end tell

     

    set theResult to do shell script "automator " & qtdworkflow

     

    return

  • by Siriusic,

    Siriusic Siriusic Jun 11, 2016 3:20 PM in response to VikingOSX
    Level 1 (11 points)
    Mac OS X
    Jun 11, 2016 3:20 PM in response to VikingOSX

    Thanks!