rccharles

Show how to code dropping files on AppleScript icon works

Mar 9th, 2021
709
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2.   Demonstration of how dropping files on AppleScript icon works.  Shows how to debug via on run path. Shows items added to folder.
  3.  
  4.  Save as an Application Bundle.  Don't check anything.
  5.  
  6.  Shows log statement.
  7.  
  8.  It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
  9.    
  10. For testing, run in the Script Editor.
  11.     1) Click on the Event Log tab to see the output from the log statement
  12.     2) Click on Run
  13.  
  14.  
  15. Author: rccharles
  16.  
  17.  *)
  18.  
  19.  
  20. -- Gets invoked here when you run in AppleScript editor.
  21.  
  22. on run
  23.     --  debug lines
  24.     set desktopPath to (path to desktop) as string
  25.    
  26.     -- here is a log statment.
  27.     log "desktopPath = " & desktopPath
  28.    
  29.     -- Be sure to select a file on your DESKTOP.
  30.     set see to alias (desktopPath & "Picture 1.png")
  31.    
  32.     -- Simulate dropped items list.
  33.     set dropped_items to {see}
  34.    
  35.     common(dropped_items)
  36.    
  37. end run
  38.  
  39.  
  40. -- Folder actions.
  41. -- Gets invoked here when something is dropped on the folder that this script is monitoring.
  42. -- Right click on the folder to be monitored. services > Folder Action Settup...
  43.  
  44. on adding folder items to this_folder after receiving added_items
  45.    
  46.     common(added_items)
  47.    
  48. end adding folder items to
  49.  
  50.  
  51.  
  52. -- Gets invoked here when something is dropped on this AppleScript icon
  53.  
  54. on open dropped_items
  55.    
  56.     common(dropped_items)
  57.    
  58. end open
  59.  
  60.  
  61.  
  62. on common(dropped_items)
  63.    
  64.     -- Write a message into the event log.
  65.     log "  --- Starting on " & ((current date) as string) & " --- "
  66.     tell application "Script Editor"
  67.         activate
  68.     end tell
  69.    
  70.    
  71.     log "class = " & class of dropped_items
  72.    
  73.    
  74.     repeat with droppedItem in dropped_items
  75.         log "The droppedItem is " & droppedItem & "; class = " & class of droppedItem
  76.        
  77.         display dialog "The droppedItem is " & droppedItem giving up after 3
  78.     end repeat
  79.    
  80.    
  81. end common
  82.  
  83.  
  84.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×