Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on run {input, parameters}
- tell application "System Events"
- if application process "Adobe Photoshop CC 2017" exists then
- set photoshopLaunched to true
- else
- set photoshopLaunched to false
- end if
- end tell
- if photoshopLaunched is false then
- tell application "Adobe Photoshop CC 2017" to activate
- end if
- set pathList to {}
- set fileList to {}
- set clipsend to ""
- set theYear to (year of (current date)) as string
- repeat with thisFile in input
- --builds fileList out of input from Automator
- copy thisFile to the end of fileList
- end repeat
- repeat with fileAlias in fileList
- --repeats per file, building PathList and resizing in Photoshop
- set filePath to (POSIX path of fileAlias)
- try
- set oldDelims to AppleScript's text item delimiters -- save their current state
- set AppleScript's text item delimiters to {"/"} -- declare new delimiters
- set theFileName to (last text item of filePath)
- set AppleScript's text item delimiters to oldDelims -- restore them
- on error
- set AppleScript's text item delimiters to oldDelims -- restore them in case something went wrong
- end try
- set fileString to (characters 1 thru ((offset of "." in theFileName) - 1) of theFileName) as string
- set fileWithPath to (characters 1 thru ((offset of "." in filePath) - 1) of filePath) as string
- set theFileName to (fileWithPath & "-6c.jpg")
- copy theFileName to the end of pathList
- tell application "Adobe Photoshop CC 2017"
- try
- open file (POSIX path of fileAlias)
- on error
- tell me to delay 5
- activate
- open file (POSIX path of fileAlias)
- end try
- set theDocument to current document
- set w to width of theDocument
- set h to height of theDocument
- if (w = 312) then
- -- this is a watch screenshot
- do action "Watch Canvas" from "Default Actions"
- set theOrientation to "vertical"
- else
- -- not a watch screenshot
- if (w - 20) > h then
- set theOrientation to "horizontal"
- resize image theDocument width 1360
- else
- set theOrientation to "vertical"
- resize image theDocument width 680
- end if
- end if
- export theDocument in theFileName as save for web with options {class:save for web export options, web format:JPEG, quality:40}
- close theDocument saving no
- if theOrientation = "horizontal" then
- set clipsend to (clipsend & "<figure><img src=\"https://sixcolors.com/images/content/" & theYear & "/" & fileString & "-6c.jpg\" alt=\"\" />" & return & "<figcaption></figcaption>" & return & "</figure>" & return & return)
- else
- 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)
- end if
- if photoshopLaunched is false then
- quit
- end if
- end tell
- end repeat
- tell application "Transmit"
- activate
- -- Prevent interactive alerts from popping up during script execution
- set SuppressAppleScriptAlerts to true
- set myFave to item 1 of (favorites whose name is "Six Colors")
- -- Create a new window (and thus a single tab) for the script
- tell current tab of (make new document at end)
- connect to myFave
- change location of remote browser to path ("/doc/images/content/" & theYear & "/")
- tell remote browser
- repeat with theFileName in pathList
- --repeats upload for all files
- upload item at path theFileName
- end repeat
- end tell
- close
- end tell
- end tell
- set the clipboard to (clipsend)
- display notification ((number of items in pathList) as string) & " images were processed."
- delay 2
- return input
- end run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement