Advertisement
applehelpwriter

LSQuarantine script

Mar 1st, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###########################################################
  2. -->> ABOUT
  3. ###########################################################
  4. (*
  5.  
  6. Phil Stokes -- 2017
  7. applehelpwriter.com
  8. sqwarq.com
  9.  
  10. *)
  11. ###########################################################
  12. -->> DESCRIPTION
  13. ###########################################################
  14. (*
  15.  
  16. See a history of your downloads that were quarantined
  17.  
  18. *)
  19. ###########################################################
  20. -->> USAGE
  21. ###########################################################
  22. (*
  23.  
  24. Click to run. If you're playing in Sierra, you can change the default font size in Notes preferences. If you're on an earlier version of macOS, you might want to cut and paste the text out of notes and into a text editor if it's too small.
  25.  
  26. *)
  27. ###########################################################
  28. -->> IMPORT STATEMENTS
  29. ###########################################################
  30.  
  31. use AppleScript version "2.4" -- Yosemite (10.10) or later
  32. use scripting additions
  33. use framework "Foundation"
  34.  
  35.  
  36. ###########################################################
  37. -->> VARIABLES
  38. ###########################################################
  39. set d to current date
  40. set fileName to "Quarantine Report (app -- download url -- website url -- date)"
  41. property NSString : a reference to current application's NSString
  42.  
  43.  
  44. ###########################################################
  45. -->> HANDLERS
  46. ###########################################################
  47.  
  48. on replaceString:oldChar withString:newChar inString:source_string
  49. set s_String to NSString's stringWithString:source_string
  50. set old_string to NSString's stringWithString:oldChar
  51. set replace_string to NSString's stringWithString:newChar
  52. return s_String's stringByReplacingOccurrencesOfString:old_string withString:replace_string
  53. end replaceString:withString:inString:
  54.  
  55.  
  56. ###########################################################
  57. -->> COMMANDS
  58. ###########################################################
  59.  
  60. set saveTID to AppleScript's text item delimiters
  61. set AppleScript's text item delimiters to {"\r"}
  62. set quarantined_items to text items of (do shell script "sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineAgentName, LSQuarantineDataURLString, LSQuarantineOriginURLString, date(LSQuarantineTimeStamp + 978307200, \"unixepoch\") as downloadedDate from LSQuarantineEvent order by LSQuarantineTimeStamp' | sort ")
  63. set AppleScript's text item delimiters to saveTID
  64. set theString to ""
  65.  
  66.  
  67. repeat with i from 1 to count of quarantined_items
  68. set this_item to item i of quarantined_items
  69. set this_item to this_item & "<br></br>"
  70. set theString to theString & this_item
  71. end repeat
  72.  
  73. set theString to (my replaceString:"|" withString:" - " inString:theString) as text
  74.  
  75. tell application "Notes"
  76. activate
  77. tell account "iCloud"
  78. tell folder "Notes"
  79. make new note with properties {name:fileName, body:theString}
  80. end tell
  81. end tell
  82. end tell
  83. ###########################################################
  84. #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement