Skip to main content
Participant
May 20, 2008
Question

PSCS3 Mac: Can't get Applescript to open "desktop:folder:file.jpg"

  • May 20, 2008
  • 6 replies
  • 809 views
I have Photoshop CS3 and am scripting a lengthy workflow, and part of it requires that I get Metadata out of files using Photoshop.

I can not get Photoshop to open a file. Once I have the file open, I can get the metadata out using UI scripting, but I have tried numerous approaches to open files and it has me stumped.

I am making it as a function that I can call from the main script which compares a new list of files with a list that is a few minutes old to determine which files are new and repeats with each file in the list. So the function will be getting a file name or a path.

Any help would be greatly appreciated!

Brian
This topic has been closed for replies.

6 replies

Known Participant
May 27, 2008
Brian, something like this would write you a csv to your desktop.

set inputFolder to choose folder with prompt "Where are the Images?" without invisibles
--
tell application "Finder"
set filesList to files in inputFolder
end tell
--
repeat with aFile in filesList
set fileIndex to 0
tell application "Finder"
set theFile to aFile as alias
set theFileName to name of theFile
end tell
tell application "Adobe Photoshop CS2"
activate
open theFile
set docRef to the current document
tell docRef
set info_credit to get (credit of info) -- result as Unicode text
set {text:plainText} to (info_credit as string)
set info_credit to plainText
--
set info_instructions to get (instructions of info) -- result as Unicode text
set {text:plainText} to (info_instructions as string)
set info_instructions to plainText
--
set info_trans_ref to get (transmission reference of info) -- result as Unicode text
set {text:plainText} to (info_trans_ref as string)
set info_trans_ref to plainText
end tell
my writelog(info_credit, info_instructions, info_trans_ref)
close current document without saving
end tell
end repeat
--
set ReadFile to ((path to desktop folder) as text) & "Image Meta-Data Log.txt" as alias
tell application "TextEdit"
activate
open ReadFile
tell document 1
delete paragraph 1
save in ReadFile
end tell
end tell
--
on writelog(info_credit, info_instructions, info_trans_ref)
set theLog to ((path to desktop folder) as text) & "Image Meta-Data Log.txt"
try
open for access file the theLog with write permission
write return & {info_credit & "," & info_instructions & "," & info_trans_ref} to file the theLog starting at eof
close access file the theLog
on error
try
close access file the theLog
end try
end try
end writelog
Participant
May 25, 2008
You're right of course. I just looked into the Photoshop scripting dictionary and saw the info-object you're talking about. Thanks for pointing me in the right direction. In order to get the information out of the fields in the info window, I was copying it to the clipboard and then setting the variable to the contents of the clipboard. I suspected there is a more elegant solution, but It was quick and dirty to use System Events. I don't know why it freezes for you, but I am using CS3. Maybe there's something different. Anyway, I'll show the code again when I have more.
Known Participant
May 21, 2008
Brian, forgive me if I've got this wrong but system events scripting is not required here. Credit, Instructions & Transmission Reference are all properties of the info object. Your script just freezes for me in CS2 could you explain what are you doing with the clipboard?
Participant
May 21, 2008
I got it! It needs to be an alias class path, and I had to concatenate the path incrementally before finally the whole path is in one variable I could coerce into an alias.

Of course, this is just one segment of the whole workflow.

tell application "Finder"
activate
set fileList to name of (items of folder "to gallery" of desktop)
repeat
set newFileList to name of (items of folder "to gallery" of desktop)
if length of newFileList > 0 then
repeat with thisFile in newFileList
if thisFile is in fileList then
else
my PSInfoGalAdd(thisFile)
end if
end repeat
set fileList to newFileList
end if
delay 30 --This will eventually be 4 minutes
end repeat
end tell

on PSInfoGalAdd(thisFile)
tell application "Adobe Photoshop CS3"
activate

set desktopPath to path to desktop
set toGalPath to desktopPath & "to gallery:" as string
set wholePath to toGalPath & thisFile
set openIt to wholePath as alias

open openIt
tell application "System Events"
tell process "Adobe Photoshop CS3"
key code 34 using {command down, option down, shift down} --File info window
delay 4
repeat 12 times
key code 125 --down arrow to Origin
delay 0.2
end repeat
repeat 5 times
key code 48 --tab to credit
delay 0.2
end repeat
key code 8 using command down --copy
delay 0.3
set credit to the clipboard
repeat 3 times
key code 48 --tab to instructions
delay 0.2
end repeat
key code 0 using command down --select all
delay 0.3
key code 8 using command down --copy
delay 0.3
set headline to the clipboard
key code 48 --tab to transmission reference
key code 0 using command down --select all
delay 0.3
key code 8 using command down --copy
delay 0.3
set body to the clipboard
key code 48 --tab
key code 36 --return key to dismiss info window
end tell
end tell
end tell
end PSInfoGalAdd
Participant
May 21, 2008
Script Editor highlights the line, -open file "Desktop:to gallery:GretaMug.JPG"- saying, "Adobe Photoshop CS3 got an error: File some object wasn't found." Here's the code:

tell application "Adobe Photoshop CS3"
activate
open file "Desktop:to gallery:GretaMug.JPG"
tell application "System Events"
tell process "Adobe Photoshop CS3"
key code 34 using {command down, option down, shift down} --File info window
delay 4
repeat 12 times
key code 125 --down arrow to Origin
delay 0.2
end repeat
repeat 5 times
key code 48 --tab to credit
delay 0.2
end repeat
key code 8 using command down --copy
delay 0.3
set credit to the clipboard as text
repeat 3 times
key code 48 --tab to instructions
delay 0.2
end repeat
key code 0 using command down --select all
delay 0.3
key code 8 using command down --copy
delay 0.3
set headline to the clipboard as text
key code 48 --tab to transmission reference
key code 0 using command down --select all
delay 0.3
key code 8 using command down --copy
delay 0.3
set body to the clipboard as text
key code 48 --tab
key code 36 --return key to dismiss info window
end tell
end tell
end tell
Participating Frequently
May 20, 2008
Let's see the code.

Carl.