I am trying to get Photoshop to determine if a selection is present or not. If not, I wanted a dialog box to appear.
This script is returning “true” no matter if I have a selection or not?
Granted the code is wrong.
Can anyone help fix this? - If the solution is difficult, please don’t worry about it - I have already gotten enough help from you all
Please
tell application "Adobe Photoshop CS"
activate
if (exists selection of current document) then
return
else
display dialog "You must have an active selection" buttons {"Cancel"} default button 1 with icon 2
return
end if
end tell
Before you give up on this altogether, Jeff, there might be a couple of last resorts worth trying.
Either of the following seems to work fairly well in PS 7. Hopefully, one of them (or something close) will do the trick for you in CS…
tell application "Adobe Photoshop CS"
activate
set storedClipboard to the clipboard
try
copy
set the clipboard to storedClipboard
on error number -10000
set the clipboard to storedClipboard
display dialog "You must have an active selection." buttons {"Cancel"} default button 1 with icon 2
end try
(* continue with your script here... *)
end tell
Or:
tell application "Adobe Photoshop CS"
activate
tell application "System Events" to set noSelection to not enabled of ¬
menu item "Copy" of menu "Edit" of menu bar 1 of process "Adobe Photoshop CS"
if noSelection then display dialog "You must have an active selection." buttons {"Cancel"} default button 1 with icon 2
(* continue with your script here... *)
end tell
Kai,
I really was about to give up on this. What a nice surprise, I can’t believe you got this to work! With your help this script is a reality.
I now have a script that will delete “all” the inverse of a selection, including the pixels that exist outside the canvas area.
Below is the script that I call, “Delete All The Inverse” :
Thank you so much for your help:
-jeff
-- Delete All The Inverse
tell application "Adobe Photoshop CS"
activate
tell application "System Events" to set noSelection to not enabled of ¬
menu item "Copy" of menu "Edit" of menu bar 1 of process "Adobe Photoshop CS"
if noSelection then display dialog "You must have an active selection." buttons {"Cancel"} default button 1 with icon 2
(* continue with your script here... *)
set theLayerName to name of current layer of document 1 as string
set the name of current layer of document 1 to "DeletedLayer"
tell application "System Events" to keystroke "j" using {command down, shift down}
delete layer "DeletedLayer" of document 1
set name of current layer of document 1 to theLayerName
end tell