Dear macscripter community.
My name is Torsten and with your help, I want to create a workflow solution for filing book cover contests that I enter on 99d. I think this would be a great thing to have for a lot of artists working on mac and it would be adaptable in part or whole for any design project that a freelancer might have.
This is my first post and I have read the rules and posting guidelines. All the parts of this solution have probably been posted on this site already. I did not search because I would like this thread to be a howto and complete with all the steps and solutions in one place for people to have.
So I am hoping for a fairly concise evolution of solving the various steps towards a working solution.
It should work on any mac involving photoshop and illustrator from adobe. I use CS6 but it should work with the newest version too of course. If all goes well I will write up the howto in one nice post at the end of this thread.
The basic functionality would be this:
Create and name the folders and files for the project as in:
Folder name: date-title-author
Then the following files should be created in that folder:
1 PSD file named ‘title’ with the amazon format 1653x2500 pixels, complete with layers for typography (title, subtitle, author) and a background (black or white).
1 AI file named ‘title’ same dimensions as the PSD for typography.
1 textfile that has the ‘brief’ of the Contest Holder named ‘brief-title’. (empty)
1 textfile that will hold any stockimage names used and their urls. (empty)
Sometimes the brief has a zip file with examples/docs attached. This zip should be downloaded into the project folder and expanded.
The first script should be a right click service(?) like ‘create book cover project’ that brings up a window where I can enter/paste the information (browser with the brief window is open):
date, title, subtitle, author. date-title-author should be used for the folder name and subtitle should be included in the layers of the PSD. The creation of the PSD would be a photoshop action running at the end of the script (I think there is a problem with PSD reporting back that the action is finished…). Creation of the AI file would be at the end too, I think they can be launched together?
When designing a book cover I use stock images often. They come from sites like unsplash and pixababy mostly, sometimes from paid sites like depositphotos or shutterstock.
Ideally when I find a good image I would like to right click on the safari page and have a service download the image into the proper folder, let me enter a name and then write that name and the corresponding url into the ‘stockimage-url’ textfile that had been created in the create book cover workflow above. Once that is done it would be great if the image was opened in photoshop where I could then call an action to place it on a layer in the project file.
So my first question is how to bring up the window to enter the information for the project files. Folder name etc. and then have the script create the Folder from that information.
Second would be to launch photoshop and create a new file in this folder using the title as the filename and then inside PS launch the action that creates the typography layers (title, subtitle, author). I have that action in place and the file could be created from a template to have the proper dimensions.
Thank you for any pointers on how to go about this and of course I appreciate if you point out how it could be done better or where there is a flaw in my logic or things that cannot be done and what to keep in mind.
Have a lovely day
Torsten
Model: macbook pro 2012
AppleScript: 2.5
Browser: Safari 601.7.7
Operating System: Mac OS X (10.10)
So my first humble step is this script that creates the folder and then creates 2 blank textfiles.
the problem is that when the textfiles are named I have to navigate to the location for the first file. I would like to ‘already’ be at that location. Also it would be nice if the 2 files were created without choosing a name - just use image-urls.txt and brief.txt by default. How can I use the same syntax as for the folder creation:
display dialog … default answer … ? I don’t need to write to the text files. Is there a make new file command? or can I use a touch file from shell?
tell application "Finder"
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set loc to choose folder "Choose Parent Folder Location"
set newfoldername to JobName
set newfo to make new folder at loc with properties {name:newfoldername}
make new folder at newfo with properties {name:"Job Materials"}
end tell
set imageURLS to open for access (choose file name) with write permission
write "image-urls" to imageURLS
close access imageURLS
set Brief to open for access (choose file name) with write permission
write "Contest-Brief" to Brief
close access Brief
end
-------------------------------------------------------------------------------------------
tell application (path to frontmost application as text) -- Returns user to frontmost app.
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set newFolderLoc to choose folder "Choose Parent Folder Location"
end tell
set newFolderName to JobName
tell application "Finder"
set newFolderRef to (make new folder at newFolderLoc with properties {name:newFolderName}) as alias
make new folder at newFolderRef with properties {name:"Job Materials"}
end tell
-------------------------------------------------------------------------------------------
Creating a text file with the Finder.
-------------------------------------------------------------------------------------------
# Creating text files with the Finder.
-------------------------------------------------------------------------------------------
set newFileName to "test_file_01.txt"
tell application "Finder"
make new file at newFolderRef with properties {name:newFileName}
end tell
-------------------------------------------------------------------------------------------
I don’t think there’s any way to click on an image in a browser and return the URL using an Automator service.
In Safari you can get the hover-link pretty easily using System Events and GUI-Scripting:
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/05/14 13:55
# dMod: 2016/03/09 18:56
# Appl: Safari, System Events
# Task: Download the item the mouse is hovering on.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @System_Events, @Download, @Mouse, @Hover
-------------------------------------------------------------------------------------------
tell application "System Events"
if quit delay ≠0 then set quit delay to 0
tell application process "Safari"
set frontmost to true
set hoveredURL to value of first static text of front window
end tell
end tell
-------------------------------------------------------------------------------------------
That doesn’t always give you a downloadable link for what you’re hovering over though (it depends upon the website).
Many things are possible via AppleScript and JavaScript, but it can get pretty complicated.
Personally I don’t like Automator and recommend FastScripts and/or Keyboard Maestro for improving the AppleScript/Automation experience.
Hi Chris, thank you for the input - I am slowly working through ‘up and running with applescript’ and here is the current version for the first part - I will change it to your version.
tell application "Finder"
set projectName to text returned of (display dialog "please enter project name:" default answer "projectName")
set titleName to text returned of (display dialog "please enter the book title:" default answer "titleName")
make new folder at "machineHD:Users:roadie:desktop-stuff:99designs:00-book-covers:" with properties {name:projectName}
set newprojectPath to folder projectName of folder "00-book-covers" of folder "99designs" of folder "desktop-stuff" of folder "roadie" of folder "Users" of startup disk
make new file at newprojectPath with properties {name:"brief-" & titleName, file type:"text"}
make new file at newprojectPath with properties {name:"image-urls-" & titleName, file type:"text"}
end tell
this creates the folder and the 2 textfiles (empty) and stores ‘just the title’ as well which I use for the textfile names and later to name the Photoshop file. I am now looking at how to fill the brief file with the info
this stores the pasted brief in a variable and now I just need to write the file filling it with the content of that variable I think …
set CHbrief to text returned of (display dialog "paste the brief" default answer "" with title "CH Brief" with icon note buttons {"done"} default button "done")
the returned text is neat and formatted so its looking good.
I tried the hovered url snippet with the unsplash site and I have to click on a download button there which opens the image url window in full res in Safari - there I click on the address bar, selecting the link and that selected text should be the input for the script to file the url and get the image.
Sorry for not making that clear - its not that I just click on one of many images on a preview page but I have the url selected, that effort is fine So what I probably need to have is a rightclick service on that selected url which stores the text in a variable and downloads the image to the folder. Maybe you know how to do that. In that process I want to be able to give the image a new name and store that with the url in the text file like:
name.jpg - url
I agree - it is going to get complicated. Right now I am learning how to call an action in Photoshop to create the file with the correct dimensions. Then I will take the Title, subtitle and Author values to create text layers in the file.
Happy to be here - have a great day.
Torsten
Keep in mind that this is a demonstration of what’s possible and not something ready for production.
Try this on the base Unsplash.com display page with the cursor hovering over an image.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/05/14 13:55
# dMod: 2016/08/30 06:26
# Appl: Safari, System Events
# Task: Download the Unsplash.com image the mouse is hovering over.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @System_Events, @Download, @Unsplash, @Mouse, @Hover
-------------------------------------------------------------------------------------------
tell application "System Events"
if quit delay ≠0 then set quit delay to 0
tell application process "Safari" to set hoveredURL to value of first static text of front window
end tell
try
set AppleScript's text item delimiters to {""", """}
set hoveredURL to text item 2 of hoveredURL
end try
set shCMD to text 2 thru -1 of "
curl -sL --user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1' " & quoted form of hoveredURL & " \\
| perl -wlne 'if ( m!<a title=\"Download photo\".+?target=.+?href=\"(.+?download)\".+?class=\"!ims ) { print $1 }'"
set downloadURL to do shell script shCMD
if downloadURL starts with "http" and downloadURL ends with "download" then
set shCMD to text 2 thru -1 of "
cd ~/Downloads;
curl -L --user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1' " & quoted form of downloadURL & " -o image.jpg"
do shell script shCMD
end if
-------------------------------------------------------------------------------------------
They’re playing some games in the HTML, so the download name of the image is completely generic for now.
It should be possible to improve on this, but I need to think about it after I’ve had coffee.
These images are not small, so the download time can be 10-30 seconds.
Personally I would not do the download directly via AppleScript. I’d script Leech to do the job. Leech is a very nice, quite inexpensive, and very scriptable downloader app. (Down to $6.00 U.S. now.)
So I would say the best for now is to click the Download button, then select the url and from that have a service that gets the image and stores the url for processing.
Really appreciate your help - this applescript is addictive - after it took me one day to figure out how to create a folder it now goes a bit faster
Here is a commented version of the workflow so far: I have noted some problems in the comments that I need to solve
-- this script sets up a project folder and creates PSD and AI files for a bookcover project
tell application "Finder"
-- get information
-- project name is the folder name - problem: I want to prepend the current date as: year-month-day-projectName
set projectName to text returned of (display dialog "please enter project name:" default answer "projectName")
-- save with correct Capitalization and spaces - these will get used in Photoshop text layers
set titleName to text returned of (display dialog "please enter the book title:" default answer "titleName")
set authorName to text returned of (display dialog "please enter the author:" default answer "authorName")
-- for these 2 we need buttons to choose none if applicable
set subtitleName to text returned of (display dialog "please enter the subtitle:" default answer "none" with icon note buttons {"none", "done"} default button "done")
set introText to text returned of (display dialog "please enter the intro text:" default answer "none" with icon note buttons {"none", "done"} default button "done")
-- here I would select the whole brief and paste it in
set CHbrief to text returned of (display dialog "paste the brief" default answer "" with title "CH Brief" with icon note buttons {"done"} default button "done")
-- problem: we also need to download the zip if the CH attached one to the brief ... not sure how to go about this - if it has to be done manually so be it but maybe
-- I can rightclick and 'service download' it storing the finderpath in a variable that gets called and moves the zip archive to the new project
-- folder and expands it, then delete the zip - would be cool
-- create project folder - path are hardcoded - you have to alter these to match your environment
make new folder at "machineHD:Users:roadie:desktop-stuff:99designs:00-book-covers:" with properties {name:projectName}
set newprojectPath to folder projectName of folder "00-book-covers" of folder "99designs" of folder "desktop-stuff" of folder "roadie" of folder "Users" of startup disk
-- problem: the titleName should be changed for these 2 files so it is lowercase, no spaces with hyphens
make new file at newprojectPath with properties {name:"brief-" & titleName, file type:"text"} -- problem: this file needs to be filled with "CHbrief" contents
make new file at newprojectPath with properties {name:"image-urls-" & titleName, file type:"text"} -- this file will get populated if we download stock images for the project
end tell
-- create a new cover in photoshop using the gathered information
tell application "Adobe Photoshop CS6" -- you need to change this to CC if you have the latest Photoshop
do action "createcover" from "Kindle actions" -- this creates a new document with the kindle dimensions 1653x2500 - you need to setup this action and call it with its name
-- for now I have arranged them so that the layer order reflects the usual positions of these texts on the cover
-- I still have to adjust them for proper font and positon
set authorTextLayer to make new art layer in the current document with properties {kind:text layer}
set properties of text object in authorTextLayer to {contents:authorName}
set introTextLayer to make new art layer in the current document with properties {kind:text layer}
set properties of text object in introTextLayer to {contents:introText}
set subtitleTextLayer to make new art layer in the current document with properties {kind:text layer}
set properties of text object in subtitleTextLayer to {contents:subtitleName}
set titleTextLayer to make new art layer in the current document with properties {kind:text layer}
set properties of text object in titleTextLayer to {contents:titleName}
end tell
-- this works fine so far
I went and bought it very cool app - thank you. Will play around with it and see how to integrate it. Of course for the workflow to share it should be a solution without having to buy anything…
Model: macbook pro 2012
AppleScript: 2.5
Browser: Safari 601.7.7
Operating System: Mac OS X (10.10)
Just want to say that I am an absolute beginner and I am learning along the way trying to create this workflow.
I have applescript 123 and other teaching resources but of course I find myself looking for a solution that requires that I understand concepts and “things” I do not know yet.
I have the current problem that I want to create the “brief-” titleName file - a textfile whose name is made up of the text “brief-” and the contents of the variable titleName. This works and the zerobyte textfile is created.
The problem is that now I want to write the contents of the CHbrief variable into this file. I am not sure that this could be accomplished in one go - create the file and fill it with the ‘brief’. If I have to open the file after creation for access and write I would need to know how to do this - even the, probably simple, targeting of the file - create the path from “brief-” and titleName is beyond me at the moment.
Any help is appreciated
Model: macbook pro 2012
AppleScript: 2.5
Browser: Safari 601.7.7
Operating System: Mac OS X (10.10)