1 2 3 Previous Next 38 Replies Latest reply: Apr 3, 2013 6:38 AM by mtimmons Go to original post
  • 30. Re: Applescript Input into Automator input...
    mtimmons Level 1 Level 1 (0 points)

    I just tried the last build you posted:

     

    Jan 27, 2013 3:21 PM -"I've updated my example of your project here."

    All I did was uncomment the shell script copy to desktop. And again, on a different Mac, 10.8.2. Clicking the "X" button on the progress bar does not work during the script. Only esp. Some pretty strange going on here.

     

    Thoughts?

  • 31. Re: Applescript Input into Automator input...
    red_menace Level 6 Level 6 (14,615 points)

    You might try sprinkling some log statements around the cancel stuff and check the Console application for the results (or any errors).  Another test would be to create a new user account and see if it does the same thing there.

  • 32. Re: Applescript Input into Automator input...
    mtimmons Level 1 Level 1 (0 points)

    I have actually been doing a lot of that. I have also ran tests with that older code "4" on a plethera of differnt macs with new users. The strang this is that I was able to get it to work with a smaller file or I guess befor the shell script.... try throwing a big file into the drop. so crazy. I'm stil trying different things.

  • 33. Re: Applescript Input into Automator input...
    mtimmons Level 1 Level 1 (0 points)

    hello,

    you don't happen to know a great / quick way to have dropped folders support do you? I am doing some research for this now..I image in will need to go in the on open?

     

    on open someItems -- Note that items dropped via CocoaAppletAppDelegate will be POSIX paths

      # POSIX paths can be coerced by using something like the following

      -- repeat with anItem in someItems -- coerce to alias in place (if needed)

      --           if class of anItem is text then set contents of anItem to (anItem as POSIX file) as text as alias

      -- end repeat

     

              set itemCount to (count someItems) -- the number of items to process

              try -- process items

      initialize()

      dispatch(someItems)

              on error errmess number errnum

                        if errnum is not -128 then display alert "Error: " & errnum message errmess

              end try

              tell me to quit -- done

    end open

     


  • 34. Re: Applescript Input into Automator input...
    red_menace Level 6 Level 6 (14,615 points)

    Yes, the on open handler is what receives the items dropped onto the application.  If you are talking about getting the contents of a folder instead of the folder itself, then you can go through the dropped items and if an item is a folder, replace it with the contained files - for example:

     

    on open someItems -- dropped items will be POSIX paths
         try -- process items
              initialize()
              
              #expand folder contents
              set myList to {}
              tell application "System Events" to repeat with anItem in someItems
                   if ((class of disk item anItem) as text) is in {"folder", "«class cfol»"} then -- folder
                        repeat with aFile in (get files of disk item anItem whose visible is true)
                             set end of myList to POSIX path of aFile -- or coerce to alias, etc
                        end repeat
                   else
                        set the end of myList to anItem -- can also coerce to alias, etc
                   end if
              end repeat
              set itemCount to (count myList) -- the number of items to process
              
              dispatch(myList)
         on error errmess number errnum
              if errnum is not -128 then display alert "Error: " & errnum message errmess
         end try
         tell me to quit -- done
    end open
    



  • 35. Re: Applescript Input into Automator input...
    mtimmons Level 1 Level 1 (0 points)

    I was able to make your suggests along with some other work. Because the way my launcher app is designed, different functions need different ways to handle folders... anyways.

     

    Have you every ouput a shell progress into your progres bar??

     

    do shell script "rsync --progres " & file & " " & /path & return??

     

    I have not done much research yet, but will be soon and figured you might have a quick example...


  • 36. Re: Applescript Input into Automator input...
    red_menace Level 6 Level 6 (14,615 points)

    Getting progress from rsync is a bit of a challenge, since even it doesn't know what it is going to do until it does it, and its progress option is more of a progress log.  One way to get a more or less normal progress bar would be to do a dry run to get some statistics, then use NSTask and periodically check/parse the output pipe/file to syncronize the progress bar, but I'm thinking that might be a bit more work than you are looking for.

  • 37. Re: Applescript Input into Automator input...
    mtimmons Level 1 Level 1 (0 points)

    yeah I figured.. I am not neccessarily need to show a real progress. I am fine just using barbar pole and under neath showing the output.. revfreshing ever .5 s or so..

     

    NewCreation_New_4ch.mov

    226263040  59%   36.31MB/s    0:00:04

     

    but.. so far I would need to tell the shell to curl to a file.. then have the progress bar get is data from that.. ......just like you said.

  • 38. Re: Applescript Input into Automator input...
    mtimmons Level 1 Level 1 (0 points)

    so!! after a few weeks and a day off.. I was able to get something done here! After research I found ways to capture the PID of a shell script.. rsync here. and then I parse that to a text file.. then gather the percent info from that. SICK! EPIC SICK!  I have also started reading Shane's book plan to slowly conver my little 'app' to a real cocoa interface.. someday.. Please send me your critques to what I did below..

     

     

    screenshot.jpg

     

    on testing(inputObjects) -- test by copying items to the desktop

              set notificationTitle to "Copy to Desktop"

              set theTargetFolder to (POSIX path of ((path to desktop folder)))

              tell progressController to showProgressWithTopText_bottomText_maxValue_("Testing…", "", (itemCount * 100) + 1)

              set percentageBefore to 0 -- resets progres percent info

              if (progressController's stopProgress) as boolean then -- cancel?

                        set my progressMessage to "Canceling…"

                        exit repeat

              else -- update the progress window for the current item

                        tell current application's NSThread to sleepForTimeInterval_(delayTime)

     

                        repeat with anItem in inputObjects

                                  set fposix to the quoted form of the POSIX path of anItem

                                  tell application "System Events" to set theName to name of disk item (anItem as text)

                                  set logOutput to POSIX path of ((path to temporary items from user domain) & "logout-" & (characters 3 thru end of ((random number) as string)) & ".txt" as string)

     

     

      -- copy file

                                  set thePID to do shell script "rsync --progress -a -h -u --exclude='.*' " & fposix & " " & theTargetFolder & " &> " & quoted form of logOutput & " & echo $!"

      -- grab its ID

                                  set processIsRunning to true

      do shell script "sleep 1"

     

      -- repeat while it's running

                                  repeat until processIsRunning is false

                                            tell application "System Events"

                                                      try

      -- if this works, the process is still running

                                                                do shell script "ps -p " & thePID

      -- so grab the last line of the output file

     

                                                                set progress to (last paragraph of (do shell script "cat " & (quoted form of logOutput)))

     

      -- set percentage to word 3 of progress

                                                                set oD to AppleScript's text item delimiters

                                                                set AppleScript's text item delimiters to {"  "}

     

                                                                set percentage to (word 2 of progress)

                                                                set AppleScript's text item delimiters to oD

     

      --get percentage value from sync output

                                                                try

                                                                          set percentageNum to percentage as number

     

                                                                on error errStr number errnum

                                                                          set percentageNum to 100

                                                                end try

     

      --get percentage difference from last repeat

                                                                set percentageDif to ((percentageNum - percentageBefore))

                                                                set percentageBefore to percentageNum

     

      -- tell progressController to setBarberPole_(true)

                                                                tell progressController --update progress by the perfect difference

      updateProgressByAmount_topText_bottomText_(percentageDif, "Uploading File(s)", progress)

                                                                          if its stopProgress then

                                                                                    my cleanup()

                                                                                    return

                                                                          end if

                                                                end tell

     

     

                                                      on error

      -- if we get here the process isn't running, so clean up

                                                                set processIsRunning to false

                                                                do shell script "rm " & quoted form of logOutput

                                                                try

                                                                          do shell script "kill -9 " & thePID

                                                                end try

                                                      end try

                                            end tell

                                  end repeat

                        end repeat

              end if

      -- notify(notificationTitle, "Files copied to Desktop.", allNames)

    end testing

1 2 3 Previous Next