├── README.md
└── TinyPNG for Automator.workflow
└── Contents
├── Info.plist
├── QuickLook
└── Preview.png
└── document.wflow
/README.md:
--------------------------------------------------------------------------------
1 | # tinypng-for-automator
2 | TinyPNG for Automator
3 |
4 | ####Remove API key
5 | `rm ~/Library/Caches/TinyPNG`
6 |
7 | This code run in Terminal.
8 |
9 | ####TinyPNG API key
10 | [Get a TinyPNG API key](https://tinypng.com/developers)
11 |
12 | The workflow code modified on "[How to compress PNG files](http://danielsetzermann.com/howto/how-to-compress-png-files)".
13 |
--------------------------------------------------------------------------------
/TinyPNG for Automator.workflow/Contents/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NSServices
6 |
7 |
8 | NSMenuItem
9 |
10 | default
11 | TinyPNG for Automator
12 |
13 | NSMessage
14 | runWorkflowAsService
15 | NSRequiredContext
16 |
17 | NSApplicationIdentifier
18 | com.apple.finder
19 |
20 | NSSendFileTypes
21 |
22 | public.image
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TinyPNG for Automator.workflow/Contents/QuickLook/Preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/utom/tinypng-for-automator/bf72effdff4ce97adfca8bc44bd8bef8e1f74b1b/TinyPNG for Automator.workflow/Contents/QuickLook/Preview.png
--------------------------------------------------------------------------------
/TinyPNG for Automator.workflow/Contents/document.wflow:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | AMApplicationBuild
6 | 417
7 | AMApplicationVersion
8 | 2.6
9 | AMDocumentVersion
10 | 2
11 | actions
12 |
13 |
14 | action
15 |
16 | AMAccepts
17 |
18 | Container
19 | List
20 | Optional
21 |
22 | Types
23 |
24 | com.apple.cocoa.string
25 |
26 |
27 | AMActionVersion
28 | 2.0.3
29 | AMApplication
30 |
31 | Automator
32 |
33 | AMParameterProperties
34 |
35 | COMMAND_STRING
36 |
37 | CheckedForUserDefaultShell
38 |
39 | inputMethod
40 |
41 | shell
42 |
43 | source
44 |
45 |
46 | AMProvides
47 |
48 | Container
49 | List
50 | Types
51 |
52 | com.apple.cocoa.string
53 |
54 |
55 | ActionBundlePath
56 | /System/Library/Automator/Run Shell Script.action
57 | ActionName
58 | Run Shell Script
59 | ActionParameters
60 |
61 | COMMAND_STRING
62 | CONFIG=~/Library/Caches/TinyPNG
63 | if [ -f $CONFIG ]; then
64 | APIKEY=$(<$CONFIG)
65 | else
66 | APIKEY="$(osascript -e 'Tell application "System Events" to display dialog "Enter a TinyPNG api key:" default answer ""' -e 'text returned of result' 2>/dev/null)"
67 | if [ $? -ne 0 ]; then
68 | # The user pressed Cancel
69 | exit 1 # exit with an error status
70 | elif [ -z "$APIKEY" ]; then
71 | # The user left the project name blank
72 | osascript -e 'Tell application "System Events" to display alert "You must enter a TinyPNG api key; cancelling..." as warning'
73 | exit 1 # exit with an error status
74 | fi
75 | echo "$APIKEY" > $CONFIG
76 | fi
77 |
78 | for f in "$@"
79 | do
80 | echo $f | while IFS= read file
81 | do
82 | filename=$(basename "$file")
83 | ext=$(echo ${filename##*.} | tr "[:upper:]" "[:lower:]")
84 | if [ -f "$file" ]
85 | then
86 | if ( [ $ext == "png" ] || [ $ext == "jpg" ] || [ $ext == "jpeg" ] )
87 | then
88 | JSON=`curl -i --user api:"$APIKEY" --data-binary @"$file" https://api.tinypng.com/shrink 2>/dev/null `
89 | if [[ $JSON == *error* ]]
90 | then
91 | ERROR=${JSON/*error\":\"/}
92 | ERROR=${ERROR/\",\"*/}
93 | osascript -e 'Tell application "System Events" to display alert "The TinyPNG api key is wrong!; cancelling..." as warning'
94 | exit 1
95 | else
96 | URL=${JSON/*url\":\"/}
97 | URL=${URL/\"*/}
98 | curl $URL>"${file}" 2>/dev/null
99 | fi
100 | fi
101 | fi
102 | done
103 |
104 | done
105 |
106 | afplay /System/Library/Sounds/Submarine.aiff
107 | osascript -e 'display notification "Compress complete!" with title "TinyPNG"'
108 | CheckedForUserDefaultShell
109 |
110 | inputMethod
111 | 1
112 | shell
113 | /bin/bash
114 | source
115 |
116 |
117 | BundleIdentifier
118 | com.apple.RunShellScript
119 | CFBundleVersion
120 | 2.0.3
121 | CanShowSelectedItemsWhenRun
122 |
123 | CanShowWhenRun
124 |
125 | Category
126 |
127 | AMCategoryUtilities
128 |
129 | Class Name
130 | RunShellScriptAction
131 | InputUUID
132 | 54D51685-2CFE-4551-AFDA-33C5AE7EBE99
133 | Keywords
134 |
135 | Shell
136 | Script
137 | Command
138 | Run
139 | Unix
140 |
141 | OutputUUID
142 | 717CA22B-11E4-4A5E-B6F4-B77EDEE9CE2E
143 | UUID
144 | 79DCB083-DC04-4EB1-8D18-0C7AEB506F40
145 | UnlocalizedApplications
146 |
147 | Automator
148 |
149 | arguments
150 |
151 | 0
152 |
153 | default value
154 | 0
155 | name
156 | inputMethod
157 | required
158 | 0
159 | type
160 | 0
161 | uuid
162 | 0
163 |
164 | 1
165 |
166 | default value
167 |
168 | name
169 | source
170 | required
171 | 0
172 | type
173 | 0
174 | uuid
175 | 1
176 |
177 | 2
178 |
179 | default value
180 |
181 | name
182 | CheckedForUserDefaultShell
183 | required
184 | 0
185 | type
186 | 0
187 | uuid
188 | 2
189 |
190 | 3
191 |
192 | default value
193 |
194 | name
195 | COMMAND_STRING
196 | required
197 | 0
198 | type
199 | 0
200 | uuid
201 | 3
202 |
203 | 4
204 |
205 | default value
206 | /bin/sh
207 | name
208 | shell
209 | required
210 | 0
211 | type
212 | 0
213 | uuid
214 | 4
215 |
216 |
217 | isViewVisible
218 |
219 | location
220 | 465.500000:637.000000
221 | nibPath
222 | /System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib
223 |
224 | isViewVisible
225 |
226 |
227 |
228 | connectors
229 |
230 | workflowMetaData
231 |
232 | serviceApplicationBundleID
233 | com.apple.finder
234 | serviceApplicationPath
235 | /System/Library/CoreServices/Finder.app
236 | serviceInputTypeIdentifier
237 | com.apple.Automator.fileSystemObject.image
238 | serviceOutputTypeIdentifier
239 | com.apple.Automator.nothing
240 | serviceProcessesInput
241 | 0
242 | workflowTypeIdentifier
243 | com.apple.Automator.servicesMenu
244 |
245 |
246 |
247 |
--------------------------------------------------------------------------------