Click to See Complete Forum and Search --> : Sendkeys and Photoshop


Robin Dude
May 10th, 2001, 02:07 PM
I've been trying to automate Adobe Photoshop 5.0 using Sendkeys. It ain't workin'.

AppActivate "Adobe Photoshop", True
For t = 0 To Files.ListCount - 1
SendKeys "^o", True
For x = 1 To 1000
DoEvents
Next x

etc, etc.

This is supposed to send CTRL-O to Photoshop, but Photoshop does not register the CTRL part and just gets O. As far as I know, Photoshop 5 doesn't support scripting in any other way and I've got an if statement in this sucker since I want to convert all the pictures of an entire directory to 800x600, then save them in a certain fashion, but only if they were larger than 800x600 to begin with.

Any ideas of what I can try? Full code follows:

Private Sub Command1_Click()
Dim DoIt As Boolean
If Text2.Text <> "" Then
If Right(Text2.Text, 1) <> "\" Then Text2.Text = Text2.Text & "\"
Text2.Visible = False
Text1.Visible = False
Command1.Visible = False
Text3.Visible = True
Files.Path = Text2.Text
AppActivate "Adobe Photoshop", True
For t = 0 To 0 'Files.ListCount - 1
SendKeys "^o", True
For x = 1 To 1000
DoEvents
Next x
SendKeys Text2.Text & Files.List(t), True
SendKeys "~", True
For x = 1 To 1000
DoEvents
Next x
SendKeys "%i", True
SendKeys "i", True
SendKeys "^c", True
AppActivate "Convert", True
Text3.Text = ""
SendKeys "^v", True
DoIt = True
If Val(Text3.Text) > 800 Then
FileCopy Text2.Text & Files.List(t), "L:\Pictures\Backup\" & Files.List(t)
ElseIf Val(Text3.Text) < 800 Then
DoIt = False
End If
AppActivate "Adobe Photoshop", True
If DoIt Then
SendKeys "800~", True
For x = 1 To 1000
DoEvents
Next x
SendKeys "^s", True
For x = 1 To 1000
DoEvents
Next x
End If
SendKeys "^w", True
End If
Next t
Text1.Text = "Done"
Text2.Visible = True
Text1.Visible = True
Command1.Visible = True
Text3.Visible = False
AppActivate "Convert"
End Sub

gordonngai
May 10th, 2001, 08:27 PM
You need put the right file in the shell to run Photoshop,
by the click button.

Dim lngTaskID As Long

Private Sub Command1_Click()

On Error GoTo Activate_Err
lngTaskID = Shell("C:\Program Files\Photoshop.EXE", vbNormalNoFocus)
AppActivate lngTaskID, False
SendKeys "^o", True

Activate_Exit:
Exit Sub

Activate_Err:
Resume Activate_Exit
End Sub

Robin Dude
May 10th, 2001, 08:33 PM
Sorry, my fault. I failed to explain that Photoshop is ALREADY RUNNING when I try this code...

I've done this before with another program (ULead's IPhoto Plus) and it worked fine. The problem here is that Photoshop is NOT REGISTERING THE CONTROL element of the Sendkeys. Thus if my command is SendKeys "^o", then Photoshop behaves as though I had simply pressed "o" and not CTRL-o.