Why won't Photoshop revert to earlier history state after image resize when scripted?

I've written an Applescript to automate watermarking and resizing images for my company. Everything generally works fine — the script saves the initial history state to a variable, resizes the image, adds the appropriate watermark, saves off a jpeg, then reverts to the initial history state for another resize and watermark loop.
The problem is when I try not to use a watermark and only resize by setting the variable `wmColor` to `"None"` or `"None for all"`. It seems that after resizing and saving off a jpeg, Photoshop doesn't like it when I try to revert to the initial history state. This is super annoying, since clearly a resize should count as a history step, and I don't want to rewrite the script to implement multiple open/close operations on the original file. Does anyone know what might be going on? This is the line that's generating the problem (it's in both the doBig and doSmall methods, and throws an error every time I ask it just to do an image resize and change current history state):
                    set current history state of current document to initialState
and here's the whole script:
property type_list : {"JPEG", "TIFF", "PNGf", "8BPS", "BMPf", "GIFf", "PDF ", "PICT"}
property extension_list : {"jpg", "jpeg", "tif", "tiff", "png", "psd", "bmp", "gif", "jp2", "pdf", "pict", "pct", "sgi", "tga"}
property typeIDs_list : {"public.jpeg", "public.tiff", "public.png", "com.adobe.photoshop-image", "com.microsoft.bmp", "com.compuserve.gif", "public.jpeg-2000", "com.adobe.pdf", "com.apple.pict", "com.sgi.sgi-image", "com.truevision.tga-image"}
global myFolder
global wmYN
global wmColor
global nameUse
global rootName
global nameCount
property myFolder : ""
-- This droplet processes files dropped onto the applet
on open these_items
  -- FILTER THE DRAGGED-ON ITEMS BY CHECKING THEIR PROPERTIES AGAINST THE LISTS ABOVE
          set wmColor to null
          set nameCount to 0
          set nameUse to null
          if myFolder is not "" then
                    set myFolder to choose folder with prompt "Choose where to put your finished images" default location myFolder -- where you're going to store the jpgs
          else
                    set myFolder to choose folder with prompt "Choose where to put your finished images" default location (path to desktop)
          end if
          repeat with i from 1 to the count of these_items
                    set totalFiles to count of these_items
                    set this_item to item i of these_items
                    set the item_info to info for this_item without size
                    if folder of the item_info is true then
  process_folder(this_item)
                    else
                              try
                                        set this_extension to the name extension of item_info
                              on error
                                        set this_extension to ""
                              end try
                              try
                                        set this_filetype to the file type of item_info
                              on error
                                        set this_filetype to ""
                              end try
                              try
                                        set this_typeID to the type identifier of item_info
                              on error
                                        set this_typeID to ""
                              end try
                              if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
  -- THE ITEM IS AN IMAGE FILE AND CAN BE PROCESSED
  process_item(this_item)
                              end if
                    end if
          end repeat
end open
-- this sub-routine processes folders
on process_folder(this_folder)
          set these_items to list folder this_folder without invisibles
          repeat with i from 1 to the count of these_items
                    set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
                    set the item_info to info for this_item without size
                    if folder of the item_info is true then
  process_folder(this_item)
                    else
                              try
                                        set this_extension to the name extension of item_info
                              on error
                                        set this_extension to ""
                              end try
                              try
                                        set this_filetype to the file type of item_info
                              on error
                                        set this_filetype to ""
                              end try
                              try
                                        set this_typeID to the type identifier of item_info
                              on error
                                        set this_typeID to ""
                              end try
                              if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
  -- THE ITEM IS AN IMAGE FILE AND CAN BE PROCESSED
  process_item(this_item)
                              end if
                    end if
          end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
          set this_image to this_item as text
          tell application id "com.adobe.photoshop"
                    set saveUnits to ruler units of settings
                    set display dialogs to never
  open file this_image
                    if wmColor is not in {"None for all", "White for all", "Black for all"} then
                              set wmColor to choose from list {"None", "None for all", "Black", "Black for all", "White", "White for all"} with prompt "What color should the watermark be?" default items "White for all" without multiple selections allowed and empty selection allowed
                    end if
                    if wmColor is false then
                              error number -128
                    end if
                    if nameUse is not "Just increment this for all" then
                              set nameBox to display dialog "What should I call these things?" default answer ("image") with title "Choose the name stem for your images" buttons {"Cancel", "Just increment this for all", "OK"} default button "Just increment this for all"
                              set nameUse to button returned of nameBox -- this will determine whether or not to increment stem names
                              set rootName to text returned of nameBox -- this will be the root part of all of your file names
                              set currentName to rootName
                    else
                              set nameCount to nameCount + 1
                              set currentName to rootName & (nameCount as text)
                    end if
                    set thisDocument to current document
                    set initialState to current history state of thisDocument
                    set ruler units of settings to pixel units
          end tell
  DoSmall(thisDocument, currentName, initialState)
  DoBig(thisDocument, currentName, initialState)
          tell application id "com.adobe.photoshop"
                    close thisDocument without saving
                    set ruler units of settings to saveUnits
          end tell
end process_item
to DoSmall(thisDocument, currentName, initialState)
          tell application id "com.adobe.photoshop"
                    set initWidth to width of thisDocument
                    if initWidth < 640 then
  resize image thisDocument width 640 resample method bicubic smoother
                    else if initWidth > 640 then
  resize image thisDocument width 640 resample method bicubic sharper
                    end if
                    set myHeight to height of thisDocument
                    set myWidth to width of thisDocument
                    if wmColor is in {"White", "White for all"} then
                              set wmFile to (path to resource "water_250_white.png" in bundle path to me) as text
                    else if wmColor is in {"Black", "Black for all"} then
                              set wmFile to (path to resource "water_250_black.png" in bundle path to me) as text
                    end if
                    if wmColor is not in {"None", "None for all"} then
  open file wmFile
                              set wmDocument to current document
                              set wmHeight to height of wmDocument
                              set wmWidth to width of wmDocument
  duplicate current layer of wmDocument to thisDocument
                              close wmDocument without saving
  translate current layer of thisDocument delta x (myWidth - wmWidth - 10) delta y (myHeight - wmHeight - 10)
                              set opacity of current layer of thisDocument to 20
                    end if
                    set myPath to (myFolder as text) & (currentName) & "_640"
                    set myOptions to {class:JPEG save options, embed color profile:false, quality:12}
  save thisDocument as JPEG in file myPath with options myOptions appending lowercase extension
                    set current history state of current document to initialState
          end tell
end DoSmall
to DoBig(thisDocument, currentName, initialState)
          tell application id "com.adobe.photoshop"
                    set initWidth to width of thisDocument
                    if initWidth < 1020 then
  resize image thisDocument width 1020 resample method bicubic smoother
                    else if initWidth > 1020 then
  resize image thisDocument width 1020 resample method bicubic sharper
                    end if
                    set myHeight to height of thisDocument
                    set myWidth to width of thisDocument
                    if wmColor is in {"White", "White for all"} then
                              set wmFile to (path to resource "water_400_white.png" in bundle path to me) as text
                    else if wmColor is in {"Black", "Black for all"} then
                              set wmFile to (path to resource "water_400_black.png" in bundle path to me) as text
                    end if
                    if wmColor is not in {"None", "None for all"} then
  open file wmFile
                              set wmDocument to current document
                              set wmHeight to height of wmDocument
                              set wmWidth to width of wmDocument
  duplicate current layer of wmDocument to thisDocument
                              close wmDocument without saving
  translate current layer of thisDocument delta x (myWidth - wmWidth - 16) delta y (myHeight - wmHeight - 16)
                              set opacity of current layer of thisDocument to 20
                    end if
                    set myPath to (myFolder as text) & (currentName) & "_1020"
                    set myOptions to {class:JPEG save options, embed color profile:false, quality:12}
  save thisDocument as JPEG in file myPath with options myOptions appending lowercase extension
                    set current history state of current document to initialState
          end tell
end DoBig

As many others here I use JavaScript so I can’t really help you with your problem.
But I’d like to point to »the lazy person’s out« – with many operations that result in creating a new file on disk I simply duplicate the image (and flatten in the same step) to minimize any chance of damaging the original file if the Script should not perform as expected.

Similar Messages

  • Why won't Photoshop Elements 12 open?

    After being away for 3 months, I attempted to open and use PSE 12 and it does not open.  Today I uninstalled and reinstalled thinking that would help, but it doesn't.  It appears as though it's going to open, but the little "streaming" just stops.  Your assistance in resolving this problem is greatly appreciated.

    I am not a technician so I can't go too deep in the analysis... I did all I could imagine to do, I would like that somebody from Adobe would take care of this issue finding solution to the problem.
    Inviato da smartphone Sony Xperia™
    A.T. Romano ha scritto -
    >     
    >Re: Why won't Photoshop Elements 12 open?
    >created by A.T. Romano in Photoshop Elements - View the full discussion
    >mcrip07

    >Hoping that you get a break through in your troubleshooting. Do not give up. I kept searching and searching for an answer to my Photoshop Elements 12 Full Editor not opening while the Elements Organizer 12 would. I have reams of data from October 2013 to April 2014 troubleshooting of the issue. Everything pointed to an activation issue but I could never target the place to fix until my break through came unexpectedly. And, as I found out, the SLStore Folder and SLCache Folder have "something" to do with activation according to the Adobe person who put forth what turned out to be the solution for me. Based on my encounter with this problem, I would say Windows No, Photoshop Elements activation Yes.

    >If you right click Computer, select Manage, followed by Event Viewer, Windows Logs, and Application, do you see any errors or information listed that could relate to this matter?

    >We will be watching for your progress.

    >Thanks for following up on the suggestions. Much appreciated.

    >ATR
    >     
    >Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6295113#6295113
    >     
    >Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6295113#6295113
    >     
    >To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6295113#6295113. In the Actions box on the right, click the Stop Email Notifications link.      
    >     
    >Start a new discussion in Photoshop Elements at Adobe Community
    >For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Why won't photoshop cc run portraiture 2

    why won't photoshop cc run portraiture 2?? Am I doing something wrong?

    Yes, you aren't giving us enough information to help you.
    What version of Photoshop?
    What OS version?
    Why is portraiture2 not working?
    Have you contacted the makers of that plugin?

  • Why won't Photoshop CC run on my laptop I just installed it today

    Why won't Photoshop CC run on my laptop I just installed it today. I signed out on my desktop but the laptop still will not run Photoshop CC. It starts but then closes itself down immediately after starting.

    Well it is the same Win7 that is running on my desktop and yes I have an internet connection and at that time is was hard wired not wireless. I just downloaded and installed the Photoshop and Bridge Apps. The laptop is about 2 yrs old and it is a high end machine and Photoshop6 runs on it just fine. I sure wish someone from Adobe would answer this question as it is beyond frustrating to me that this stuff works so poorly and you can never get a good answer out of them about anything ever.

  • Why won't photoshop elements download for me

    why won't photoshop elements download for me

    clear your adobe.com cookies or
    try a different browser or
    download from prodesigntools.com if you follow all 7 steps:  http://prodesigntools.com/tag/ddl
    and activate with your serial.
    if you have a problem dl'g, you didn't follow all 7 steps.  the most common error involves failing to meticulously follow steps 1,2 and/or 3 (which adds a cookie to your system enabling you to download the correct version from adobe.com).

  • Why won't Photoshop CS6 Extended update? I keep getting a failed to update message.

    Why won't Photoshop CS6 Extended update? I keep getting a failed to update message.

    Run the Creative Suite Cleaner Tool, reinstall the program, try again.
    Mylenium

  • Help why won't photoshop let me edit my photos anymore?

    Why won't photoshop let me edit my photos I am a photographer and my photos need more editing but photoshop will open the tools but nothing happens with any of the tools!

    Too little information …
    Could you please post a screenshot with the pertinent Panels visible?
    Boilerplate-text:
    Are Photoshop and OS fully updated and have you performed the usual trouble-shooting routines (trashing prefs by keeping command-alt-shift/ctrl-alt-shift pressed while starting Photoshop after making sure all customized presets like Actions, Patterns, Brushes etc. have been saved and making a note of the Preferences you’ve changed, 3rd party plug-ins deactivation, system maintenance, cleaning caches, font validation, etc.)?

  • HT201398 Why won't podcast app work on iPhone 5 after ios 8.1.3 update?

    Why won't podcast app work on iPhone 5 after ios 8.1.3 update?
    I've restarted the phone and itunes several times, have uninstalled and reinstalled the app on the phone and itunes separately, and it still just shows 'Installing" under the greyed out app.

    I have the same problem with an iPhone 5s. All podcast fail to work on the phone since updating to iOS 8.1.3. What is going on? Is Apple taking this problem serious?

  • I just downloaded Acrobat and it won't work. Why won't it work? I keep having it quit unexpectedly when I try to launch it.

    I just downloaded Acrobat and it won't work. Why won't it work? I keep having it quit unexpectedly when I try to launch it. I've tried uninstalling and reinstalling. I've tried restarting my computer.  Any suggestions? I fit all they system requirements.

    Hi again CueBallMcDraw,
    What operating system are you on? If your issue isn't related to your subscription being in a pending state (as I discussed in your other post), we'll look closer at what's going on with your system. But, I suspect you're going to be fine once your order finishes processing.
    Please let us know how it goes.
    Best,
    Sara

  • Why won't Aperture 2 support RAW files imported from Canon 60D when it does from my Olympus DSLR?

    Why won't Aperture 2 support RAW files imported from Canon 60D when it does from my Olympus DSLR?

    I'm afriad the fact that your Olympus dSLR is supported is no relevance.
    The Raw from every model of camera is different. Note: that's every model not every brand. So, the NEF produced by a Nikon D40 is not the same as the NEF produced by a D60, the CR2 produced by a Canon 350 is not the same as the CR2 produced by a Canon 400.
    Support for individual camera models has to be added one by one, and Apple will update the OS to work with the most recent version of the software. That's an incentive for you to keep up-to-date. So, for support for your 60D you'll need 10.6.5 plus Aperture 3 and/or iPhoto 11.
    Regards
    TD

  • Sometimes Undo is "Undo Save History State for Image"...

    Anyone know why the Undo command occasionally produces "Undo Save History State for Image" rather than a proper undo of the last operation?

    I am aware of your contribution to this forum and genuinely have utmost respect for what you say, however without getting too heavily into the semantics of the meaning of the word “bug” I would truly appreciate your thought on this …
    b_gossweiler wrote:
    If you export (or also print) an image, an entry is inserted into the develop history of the image. Although these steps (export, print, ...) cannot be physically undone, the undo removes this history step from the develop history of the image. This makes sense and - IMHO - is not a bug at all.
    Beat
    Would it not be reasonable that when a user requests an “undo” that they would expect this to undo the last thing “they” did regardless of what any background task is doing?   
    If this does occur when performing some background task on several hundred or thousand images does this mean that they could struggle to actually achieve any meaningful undo operation on what they are currently working on because they could be attempting to undo many state changes?      If so, could one consider that from a user’s perspective the undo mechanism is actually broken in this scenario?
    If they request an “undo” and it does not perform to the users reasonably expected behaviour would it not reasonably be considered at least undesirable if not a bug?
    If they perform an “undo” and they get this message have they actually undone something which might be important?   
    Even if it has no ill effects the message alone could be unsettling and confusing to users?
    You say it makes sense and I know I’m slow, but I would not expect a user to see this message when the user wants to undo for example the modification to exposure or other slider they have just changed.
    I’m not hung up on this as I have seen no ill effects other than mild inconvenience; however I would respectively appreciate your views on how this “makes sense” from a user’s perspective.

  • Why won't Photoshop use my Wacom preferences?

    OK, so this is going to be a bit of a back story because I think I know what part of the problem is...I just don't know how to fix it.
    I recently downloaded Photoshop CC onto my computer.  I already had a copy of PS CS3 on there.  When it installed, it asked if I wanted to use my settings from that.  Not seeing a problem, I said "yes".  And things were fine.  But I wanted to change the Hotkey settings on my Cintiq for CC to be different from CS3.  When I tried to change them in System Preferences, however, it didn't work.  The settings saved, but they still used the same settings as CS3.  I changed the settings in CS3 and those came over to CC.  So, clearly it is referring to CS3 for preference. So I uninstalled CS3 and removed its settings from System Preferences.  So CC defaults back to the general shortcuts for the Cintiq.  I tried to add it back into the Applications with special keys and it still isn't working. 
    My guess is it is still looking to CS3 for settings, but I don't know what I need to do to get it to stop doing that.  I really just wanted to keep my unique brushes.  Does anyone know how I can remove the connection or even just get this to stop? 
    Thanks!

    Have you set preferences in your Wacom configuration for each version of Photoshop you have installed.  It hard to do when you have several versions of Photoshop installed wnat mant hace the same icon,  I have 6 versions installed.  Wacom configuration need setting and path for each install.
    Even when I edit the saver Preferences and change the short names I can not get all six showinr in the preference panel.????\

  • Why won't my FaceTime connect? It keeps saying connection failed when trying to sign in.

    Why won't my FaceTime work? I just got this iPad new was able to FaceTime once. The next time I tried to FaceTime it said phone number incomplete. So I signed out of FaceTime and now it won't sign back in. It keeps saying connection failed check connection. I am showing I'm connected to the wireless router. What could be the issue?

    Ok, so sometimes apple's servers may crash, temporarily. Just check the following site: http://www.apple.com/uk/support/systemstatus/
    and it will notify you of any crashes. The link above is for the UK. Change to adapt to your country if you are outside of the UK. If your problem isn't listed I am sure it will be resolved within 24 hours. If this problem persists best thing is to contact apple.
    Hope this helped :)

  • Why won't my youtube loading bar load all the way?when I'm using firefox? It loads perfectly when I'm using Chrome.

    Why won't my youtube loading bar load all the way when I'm using firefox? It loads perfectly when I'm using Chrome or IE.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    * Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    * Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Why won't photoshop elements 12 editor launch/open?

    No matter how I try to activate PSE12, through the desktop shortcut, through program files, through old Photoshop works I've saved, it will not start.
    I've tried reinstalling it, but it still won't launch.
    What's strange to me is that Premier Elements, which I also have, works just fine. I can access the organizer through there, see old Photoshop works, but be unable to work on them because the editor won't load at all. No prompt on screen. No 404 ERROR or something like that, just a loading circle that goes away after a few seconds.
    I have Windows 8 and a brand new computer. Why is this happening?

    I have the exact same issue, but nothing on my computer changed!  Abode chat support twice now has refused to help me.  First time the guy cut me off; this time they told me to come here.  Looks like you have the same problem with no answer.  Not a good way to run a company!

Maybe you are looking for

  • Error while saving or submitting the page

    I have an application with sharepoint2010 and in the code behind visual studio 2012,Innitially evry module was working,but now when i am saving or submitting any page its giving me UNEXPECTED error with a co-relation id. I went through the error log,

  • Problem with IDoc scenario - IDocs do not aarive to XI

    Hi guys! I have a problem with IDoc->XI->File scenario. Colleagues send IDocs from R/3 and they are not in the XI. In R/3 they look like if they were correctly sent, however, I can not see them in sxmb monitor. BUT, when they send them again explicit

  • Failed Exchange Server Sync Question

    Hi all my exchange server has failed so had to replace it which I have now done but im unsure about the phones. All the users phones still have the contacts and emails on but there Outlooks are effectly blank. If I sync the phones will I loose all th

  • HT204291 Help with AirPlay from iPad

    I'm trying to send a video to my AppleTV from iPad. Sound is heard, but image is main menu. Any suggestions?

  • Offline music doesn't show up under artists...

    I just made some playlists available offline, however the artists from those playlsits don't show up under the artists section of the app. Artists from 'my music' are visible, but not the ones from the offline playlists. Is this how it's supposed to