Guest User

Untitled

a guest
Jan 20th, 2017
537
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on run {input, parameters}
  2.    
  3.    
  4.     tell application "System Events"
  5.         if application process "Adobe Photoshop CC 2017" exists then
  6.             set photoshopLaunched to true
  7.         else
  8.             set photoshopLaunched to false
  9.         end if
  10.     end tell
  11.    
  12.     if photoshopLaunched is false then
  13.         tell application "Adobe Photoshop CC 2017" to activate
  14.     end if
  15.    
  16.     set pathList to {}
  17.     set fileList to {}
  18.     set clipsend to ""
  19.     set theYear to (year of (current date)) as string
  20.    
  21.     repeat with thisFile in input
  22.         --builds fileList out of input from Automator
  23.         copy thisFile to the end of fileList
  24.        
  25.     end repeat
  26.    
  27.     repeat with fileAlias in fileList
  28.        
  29.         --repeats per file, building PathList and resizing in Photoshop
  30.        
  31.         set filePath to (POSIX path of fileAlias)
  32.        
  33.         try
  34.             set oldDelims to AppleScript's text item delimiters -- save their current state
  35.             set AppleScript's text item delimiters to {"/"} -- declare new delimiters
  36.            
  37.             set theFileName to (last text item of filePath)
  38.             set AppleScript's text item delimiters to oldDelims -- restore them
  39.         on error
  40.             set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong
  41.         end try
  42.        
  43.         set fileString to (characters 1 thru ((offset of "." in theFileName) - 1) of theFileName) as string
  44.        
  45.         set fileWithPath to (characters 1 thru ((offset of "." in filePath) - 1) of filePath) as string
  46.        
  47.         set theFileName to (fileWithPath & "-6c.jpg")
  48.        
  49.         copy theFileName to the end of pathList
  50.        
  51.        
  52.         tell application "Adobe Photoshop CC 2017"
  53.            
  54.             try
  55.                 open file (POSIX path of fileAlias)
  56.             on error
  57.                 tell me to delay 5
  58.                 activate
  59.                 open file (POSIX path of fileAlias)
  60.             end try
  61.            
  62.            
  63.             set theDocument to current document
  64.             set w to width of theDocument
  65.             set h to height of theDocument
  66.            
  67.             if (w = 312) then
  68.                
  69.                 -- this is a watch screenshot
  70.                
  71.                 do action "Watch Canvas" from "Default Actions"
  72.                 set theOrientation to "vertical"
  73.             else
  74.                
  75.                 -- not a watch screenshot
  76.                
  77.                 if (w - 20) > h then
  78.                     set theOrientation to "horizontal"
  79.                     resize image theDocument width 1360
  80.                 else
  81.                     set theOrientation to "vertical"
  82.                     resize image theDocument width 680
  83.                 end if
  84.                
  85.             end if
  86.            
  87.             export theDocument in theFileName as save for web with options {class:save for web export options, web format:JPEG, quality:40}
  88.             close theDocument saving no
  89.            
  90.             if theOrientation = "horizontal" then
  91.                 set clipsend to (clipsend & "<figure><img src=\"https://sixcolors.com/images/content/" & theYear & "/" & fileString & "-6c.jpg\" alt=\"\" />" & return & "<figcaption></figcaption>" & return & "</figure>" & return & return)
  92.             else
  93.                 set clipsend to (clipsend & "<figure class=\"pull-right\"><img src=\"https://sixcolors.com/images/content/" & theYear & "/" & fileString & "-6c.jpg\" alt=\"" & fileString & "\" />" & return & "<figcaption></figcaption>" & return & "</figure>" & return & return)
  94.             end if
  95.            
  96.             if photoshopLaunched is false then
  97.                 quit
  98.             end if
  99.            
  100.            
  101.         end tell
  102.        
  103.     end repeat
  104.    
  105.    
  106.     tell application "Transmit"
  107.         activate
  108.         -- Prevent interactive alerts from popping up during script execution
  109.         set SuppressAppleScriptAlerts to true
  110.        
  111.         set myFave to item 1 of (favorites whose name is "Six Colors")
  112.        
  113.         -- Create a new window (and thus a single tab) for the script
  114.         tell current tab of (make new document at end)
  115.             connect to myFave
  116.             change location of remote browser to path ("/doc/images/content/" & theYear & "/")
  117.            
  118.             tell remote browser
  119.                
  120.                 repeat with theFileName in pathList
  121.                     --repeats upload for all files
  122.                     upload item at path theFileName
  123.                 end repeat
  124.                
  125.             end tell
  126.             close
  127.         end tell
  128.     end tell
  129.    
  130.     set the clipboard to (clipsend)
  131.    
  132.     display notification ((number of items in pathList) as string) & " images were processed."
  133.     delay 2
  134.    
  135.     return input
  136.    
  137. end run
RAW Paste Data