Need a script that will put photo on white background

I am currently using CS3 Photoshop on a MacPro Intel
I have about 31,000 photos that I need to take the background out of. Most of the photos were not shot against white, black or green screens. These are mostly images of plumbing products. The majority of these images do have clipping paths. I am currently having to manually select the path, make selection, select inverse, cut the selection, save, close. I have tried to create a script to do this, but haven’t been successful in doing so yet. I have been able to create basic scripts in the past without issues, but this one has me stumped. Any help or direction would be greatly appreciated.

As long as the files do have clipping paths this should get you started. It applies the clipping path as a vector mask. All you should have to add is the save and close part. If you need help with that let me know what format you want to save and the save options.
// apply clipping path as vector mask
var clipPathIndex = clippingPathIndex();
if( clipPathIndex != -1 ){
     activeDocument.layers[ activeDocument.layers.length -1 ].name = 'Converted Background';// rename bottom layer incase isBackground
     activeDocument.pathItems[ clipPathIndex ].select();
     createVectorMask();
     activeDocument.pathItems[ clipPathIndex ].deselect();
     // or
     //activeDocument.pathItems[ clipPathIndex ].remove();
// Function: clippingPathIndex
// Description: Gets the index of the activeDocument's clipping path
// Usage: clippingPathIndex()
// Input: None
// Return: Index as Integer. -1 if there is no clipping path
function clippingPathIndex(){
     var ref = new ActionReference();
          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
     var desc = executeActionGet( ref );
     var clippingPath =  desc.getObjectValue(charIDToTypeID("Clpg"));
     return  clippingPath.getInteger(charIDToTypeID("ClpI" ));
// Function:  createVectorMask
// Description: Make vector mask from active path
// Usage: createVectorMask();
// Input: None
// Return: -1 if failed
function createVectorMask() {
  try{
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putClass( charIDToTypeID('Path') );
    desc.putReference( charIDToTypeID('null'), ref );
        var mask = new ActionReference();
        mask.putEnumerated( charIDToTypeID('Path'), charIDToTypeID('Path'), stringIDToTypeID('vectorMask') );
    desc.putReference( charIDToTypeID('At  '), mask );
        var path = new ActionReference();
        path.putEnumerated( charIDToTypeID('Path'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc.putReference( charIDToTypeID('Usng'), path );
    executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
  }catch(e){ return -1; }

Similar Messages

  • I need a script that will find the computer a user last logged into.

    I am still learning scripting, I need a script that will allow me to pull in usernames from a csv file. Find what computer they last logged into and output that to an csv file.
    I have looked all over and can't find exactly what I need.
     I found the following script but I need  to add the resuitsize unlimited but can not figure out where to put it we have a large environment. Also I need to be able to grab username from a csv file. Any assistance you can provide is appreciated.
    ##  Find out what computers a user is logged into on your domain by running the script
    ##  and entering in the requested logon id for the user.
    ##  This script requires the free Quest ActiveRoles Management Shell for Active Directory
    ##  snapin  http://www.quest.com/powershell/activeroles-server.aspx
    Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
    $ErrorActionPreference = "SilentlyContinue"
    # Retrieve Username to search for, error checks to make sure the username
    # is not blank and that it exists in Active Directory
    Function Get-Username {
    $Global:Username = Read-Host "Enter username you want to search for"
    if ($Username -eq $null){
    Write-Host "Username cannot be blank, please re-enter username!!!!!"
    Get-Username}
    $UserCheck = Get-QADUser -SamAccountName $Username
    if ($UserCheck -eq $null){
    Write-Host "Invalid username, please verify this is the logon id for the account"
    Get-Username}
    get-username resultsize unlimited
    $computers = Get-QADComputer | where {$_.accountisdisabled -eq $false}
    foreach ($comp in $computers)
    $Computer = $comp.Name
    $ping = new-object System.Net.NetworkInformation.Ping
      $Reply = $null
      $Reply = $ping.send($Computer)
      if($Reply.status -like 'Success'){
    #Get explorer.exe processes
    $proc = gwmi win32_process -computer $Computer -Filter "Name = 'explorer.exe'"
    #Search collection of processes for username
    ForEach ($p in $proc) {
    $temp = ($p.GetOwner()).User
    if ($temp -eq $Username){
    write-host "$Username is logged on $Computer"

    If you are querying by user "resultset size" will be of no use.
    You also have functions that are never used and the body code doe snot look for users.
    Here is what you scrip looks like if printed well.  It is just a jumble of pasted together and unrelated items.
    ## Find out what computers a user is logged into on your domain by running the script
    ## and entering in the requested logon id for the user.
    ## This script requires the free Quest ActiveRoles Management Shell for Active Directory
    ## snapin http://www.quest.com/powershell/activeroles-server.aspx
    Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
    $ErrorActionPreference = "SilentlyContinue"
    # Retrieve Username to search for, error checks to make sure the username
    # is not blank and that it exists in Active Directory
    Function Get-Username {
    $Global:Username = Read-Host "Enter username you want to search for"
    if ($Username -eq $null) {
    Write-Host "Username cannot be blank, please re-enter username!!!!!"
    Get-Username
    $UserCheck = Get-QADUser -SamAccountName $Username
    if ($UserCheck -eq $null) {
    Write-Host "Invalid username, please verify this is the logon id for the account"
    Get-Username
    get-username resultsize unlimited
    $computers = Get-QADComputer | where { $_.accountisdisabled -eq $false }
    foreach ($comp in $computers) {
    $Computer = $comp.Name
    $ping = new-object System.Net.NetworkInformation.Ping
    $Reply = $null
    $Reply = $ping.send($Computer)
    if ($Reply.status -like 'Success') {
    #Get explorer.exe processes
    $proc = gwmi win32_process -computer $Computer -Filter "Name = 'explorer.exe'"
    #Search collection of processes for username
    ForEach ($p in $proc) {
    $temp = ($p.GetOwner()).User
    if ($temp -eq $Username) {
    write-host "$Username is logged on $Computer"
    I suggest finding the original code then use the learning link at the top of this page to help you understand how it works in Powershell.
    ¯\_(ツ)_/¯

  • I NEED A FORM THAT WILL PUT NAME IN ALPHABETIC ORDER.  THIS FORM NEEDS TO HAVE COLUMNS WITH HEADERS.

    I NEED A FORM THAT LISTS NAMES IN ALPHBETIC ORDER ON THE LEFT SIDE GOING DOWN.  THIS FORM ALSO NEEDS COLUMNS THAT HAVE PRODUCT IDENTIFICATION ON THE TOP OF THE COLUMNS.

    Hi,
      Is your question in the context of the responses that you collect (this is the View Responses tab) or the actual form that your end users will see?
    In a nutshell, (1)  a field in your form corresponds to a column in the responses table. (2) the caption text of the form field will be the column header (show up at the top of the column). (3) to list names in alphabetical in your form, you can use choices fields, like multiple choices field or drop down field - you will have to enter the name in alphabetical order manually.
    Hope this helps,
    Thanks,
    Lucia

  • Looking for a script that will size photos down and give unique filenames

    Here's the challenge:
    I have a bunch of photos that need to be sized down to three different types of thumbnails, each group of thumbnails needs to have a specific prefix to the filename while keeping the rest of filename in tact.
    So example:
    I start out with a photo 1400 x 933
    That photo needs to be sized down to 3 different smaller sizes: 630 x 420, 210 x 140 and 140 x93 (all of those have the same aspect ratio as 1400 x 933). So far this is a simple Action in Photoshop.
    The trick I can't figure out is that these photos need to have a specific file naming convention. Say for example the 1400 x 933 photo we start out with is named w_paul_001.jpg the other photos once sized down need to be: x_paul_001.jpg (for the 630x420), y_paul_001.jpg (for the 210 x 140) and z_paul_001.jpg (for the 140x93).
    How I do dat?

    This will do what you want:
    var srcDoc = app.activeDocument;
    var imgNum = srcDoc.name.substring(7, (srcDoc.name.length)-4);
    var myJpgQuality = 12
    var sizeArray = [
    [1400, 933, "x_paul_"],
    [630,  420, "y_paul_"],
    [100,  100, "z_paul_"]
    for (var i=0; i<sizeArray.length; i++)
      var shrinkWidth =  sizeArray [i][0];
      var shrinkHeight = sizeArray [i][1];
      var mySaveName = sizeArray [i][2];
      var id428 = charIDToTypeID( "Dplc" );
      var desc92 = new ActionDescriptor();
      var id429 = charIDToTypeID( "null" );
      var ref27 = new ActionReference();
      var id430 = charIDToTypeID( "Dcmn" );
      var id431 = charIDToTypeID( "Ordn" );
      var id432 = charIDToTypeID( "Frst" );
      ref27.putEnumerated( id430, id431, id432 );
      desc92.putReference( id429, ref27 );
      var id433 = charIDToTypeID( "Nm  " );
      desc92.putString( id433, mySaveName );
      executeAction( id428, desc92, DialogModes.NO );
      activeDocument.resizeImage(shrinkWidth, shrinkHeight, 72, ResampleMethod.BICUBIC);
      filePath = srcDoc.path + '/' + mySaveName + imgNum + '.jpg';
      var jpgFile = new File(filePath);
      jpgSaveOptions = new JPEGSaveOptions();
      jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
      jpgSaveOptions.embedColorProfile = true;
      jpgSaveOptions.matte = MatteType.NONE;
      jpgSaveOptions.quality = myJpgQuality;
      activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
      app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

  • Need a Script that will count different codes and enter in another field

    I am using ES2,  I have a form which users enter codes (50 different codes) in a code field.  I need for the corresponding toatl box for each code to increase by 1 for each time the corresponding code is entered.  Have just started using ES2 and any help would be welcome.
    TY

    I am using ES2,  I have a form which users enter codes (50 different codes) in a code field.  I need for the corresponding toatl box for each code to increase by 1 for each time the corresponding code is entered.  Have just started using ES2 and any help would be welcome.
    TY

  • We need a script that will select clipping path for multiple images in indesign

    this is what we have, but it's not working:
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
    app.doScript(resetAllClippingPathsToActiveDoc, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Reset all Clipping Paths of the Active Document"); 
    function resetAllClippingPathsToActiveDoc(){ 
        var d=app.activeDocument; 
        var allGraphicsInDoc = d.allGraphics; 
        for(var n=0;n<allGraphicsInDoc.length;n++){ 
            if(allGraphicsInDoc[n].hasOwnProperty("clippingPath")){allGraphicsInDoc[n].clippingPath.c lippingType = ClippingPathType.PHOTOSHOP_PATH};
                allGraphicsInDoc[n].clippingPath.appliedPathName = "Path 1"; 

    this is what we have, but it's not working:
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
    app.doScript(resetAllClippingPathsToActiveDoc, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Reset all Clipping Paths of the Active Document"); 
    function resetAllClippingPathsToActiveDoc(){ 
        var d=app.activeDocument; 
        var allGraphicsInDoc = d.allGraphics; 
        for(var n=0;n<allGraphicsInDoc.length;n++){ 
            if(allGraphicsInDoc[n].hasOwnProperty("clippingPath")){allGraphicsInDoc[n].clippingPath.c lippingType = ClippingPathType.PHOTOSHOP_PATH};
                allGraphicsInDoc[n].clippingPath.appliedPathName = "Path 1"; 

  • I need a script that copies the filename into the file

    I need a script that copies the filename into 4th column of each line in the text doc file.
    I have over 2000 different file names each containing 6 columns and ~50-100 rows.
    I can do this manually using this script:
    awk '{print $1"\t"$2"t\"$3"\t <name> \t"$6}'
    But I would like an automation command or script. Is there any command that I can use instead of <name> that will copy the filename into the column?
    Thanks
    Monica

    Oops, I forgot the redirect to a file. It's not a good idea to edit files in place. A script could fail and you're left with at least one file ruined. It's better to create new files then delete the old files.
    for file in *; do
        while read col1 col2 col3 col4 col5 col6; do              
            printf "%s\t%s\t%s\t%s\t%s\n" $col1 $col2 $col3 $file $col6
        done < $file > n$file
    done
    You could narrow the files listed such as
    for file in *.tsv
    and redirect the new files to another directory. Such as
    done < $file > /absolute/path/to/directory/$file

  • Script that will help validate if there is any data loss after a DB restore

    Hi,
    I need to write a single script that will perform the following
    operations:
    1)return me the highy accessed tables across all databases.
    2)List the count, Min and Max system date of the highy accessed tables returned from step 1.
    The idea is to validate if there is any data loss to the highly transactional tables after a database restore operation has been performed.
    Thanks.

    Hello,
    I would also like you to see nice blog by Aron,you can modify the script a bit to change according to your need
    http://sqlblog.com/blogs/aaron_bertrand/archive/2008/05/06/when-was-my-database-table-last-accessed.aspx
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    Hello Shanky,
    The post would not be helpful too much for OP's requirement. The post was talking about when was the database last accessed. DMLs are not capturing in the script and also there will be many variant forms that can be applied for DML. Hence, I do not think,
    the script would help too much. 
    Or Am I missing something? 
    Latheesh as i mentioed OP has to modify the script little bit may be add User_seek,user_update,user_scans.Still IMO there is no *perfect* way to actually analyze this.So I pointed out point in my original post.Also unless he has some timestamp he cannot
    see min time when it was accessed ,max time can be taken from last user seek,scan,lookup time. Motive was to lethim know what he was trying to achieve cannot be axactly obtained by using sys.dm_index_usage_stats.Below query will give most accessed table
    : Source (Query)
    SELECT
    t.name AS 'Table',
    SUM(i.user_seeks + i.user_scans + i.user_lookups)
    AS 'Total accesses',
    SUM(i.user_seeks) AS 'Seeks',
    SUM(i.user_scans) AS 'Scans',
    SUM(i.user_lookups) AS 'Lookups'
    FROM
    sys.dm_db_index_usage_stats i RIGHT OUTER JOIN
    sys.tables t ON (t.object_id = i.object_id)
    GROUP BY
    i.object_id,
    t.name
    ORDER BY [Total accesses] DESC
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Is there an AppleScript or Automator Script that will wake a Mac from Sleep?

    Is there an AppleScript or Automator Script that will wake a Mac from Sleep?

    Frank and All,
    The following answer to your question above is complicated, but I hope it explains why my question was formed with so much frustration in it.
    I have an OpenOffice(OO) Macro that was launched with Calendar at 6pm each business night. It ran properly in all Apples operating systems until I Hit Maverick(OSX10.9). From then on, the AppleScript would run from one to 3 days, then would disappear from the Calendar entry. The Calendar alert would still run, but the "OpenFile" section of the alert would disappear. I also was running elgato EyeTV HD during the day, so I would use energy saver to put my MacBook Pro to sleep at 12 Midnight and wake it again at 9am. I picked up a used Mac Mini to do the EyeTV stuff, provide AppleTV the files in H264 format through iTunes' media share, and found it had plenty of power to do the 6pm automated stuff simultaneously as well. Because I still wanted to run the OpenOffice Macro on my MacBook Pro at 6pm, and wanted to use it for a host of other things when I was on the road, I wanted it to sleep most of the time and only wake up automatically to run the 6pm OO Macro. When I called Apple about the issue I was having with Maverick and Calendar loosing the OpenFile command as part of the Alert Message, they told me the no longer supported answering AppleScript Questions but they now would support Automator questions. I pointed out that the OpenFile would also fail after one to three days if I used a Calendar Alert to launch an Automator App. At first, I did not like Automator, but now I see why Apple is pushing us to use it. Automator adds a TIME STAMP ID to the Apps developed in Automator so the first time you launch the App after a change to it, you must reply to a dialog message saying that this is the first time you are running this version of the App. If a Scammer has replaced your app with one that can reek havoc on your computer, the replacement app will not run unless you are there to agree that you know where the modified app came from and click the OK button to continue (BRILLIANT, Enhanced Security idea on Apples part). I also noticed that after Mountain Lion, the Applescript delay timing was all screwed up as well. Well I tried to use LaunchD Task Scheduler to circumvent the Calendar Problem and that worked until I upgraded to Yosemite Last week. Then LaunchD no longer worked and I am only into a few days of using The Calendar Launched Automator App to see if it will continue to run.
    But I think I solved the dilemma I was having with opening an Automator App in a Sleeping Mac. I Googled up the following question, "AppleScript to wake up computer".  I went thru several complex responses until I found this on that is INCREDIBLE EASEY! What came back was a brettterpstra.com  response from Feb 20th,2014. What it said, in a Quick Tip: caffeinated your Terminal Article,  if you wanted to wake a Mac from sleep, use the Terminal command named "Caffeine -u -t 1". I placed it in an Automator Most Used Action called "Run Shell Script -- Caffeine -u -t 1" and it worked!  Now, I can put my Mac to Sleep but at 6pm, the Automator App will launch, run the "Caffeine -u- -t 1" command and proceed to work as if I had awakened the Mac From Sleep mode by pressing a keyboard key and had run the Automator Script with a double click.
    Sorry for the long, drawn-out reply, but maybe this will help others.

  • HT1386 why are there 0's in some folders that i put photos in in iPhoto when I veiw it in iTunes?

    why are there 0's in some folders that i put photos in in iPhoto when I veiw it in iTunes?

    Those files should be being created in folders of the form:
    <User's Music>\iTunes\Album Artwork\Cache|Download\<GUID>\<##>\<##>\<##>
    The <GUID> in your case is 0CDB362F24AD473A...
    If they are appearing anywhere else I would suspect a permissions problem. iTunes just spits them out where it can. Similar problems can sometimes cause it to drop files on the desktop.
    Repair Permissions
    Right-click on your main iTunes folder and click Properties, then go to the Security tab and click Advanced. If necessary grant your account and system full control to this folder, subfolders and files, then tick the option to replace permissions on child objects which will repair permissions throughout the library. This is the XP dialog but Windows 7 shouldn't be too different.
    Once you've repaired the permissions search for all files of the form *.itc2 in the music folder and delete them, then start iTunes. iTunes will rebuild the artwork cache in the correct location as you scroll through your library.
    tt2

  • I need an application that will turn off my iPhone on the home screen just by a one click since my power button has sank and is no longer working--anyone have ideas?? I don't like having to use assistive touch and hit three buttons to lock my screen

    I need an application that will turn off my iPhone on the home screen just by a one click since my power button has sank and is no longer working--anyone have ideas?? I don't like having to use assistive touch and hit three buttons to lock my screen

    No such app exisits or can exist.  Apple doesn't allow 3rd party apps to access core functions of the phone.  Time to get your phone replaced or repaired if assistive touch doesn't needs your needs.

  • Looking for a script that will find broken links

    I create long documents in InDesign, and I often have 50-75 Indesign documents in my InDesign book. Because what I do is production publishing, at any one time I'll have a half dozen similar books under construction. All the books contain the same chapters (as far as file name an basic content). I need a script that I can run on the final PDF for each project to make sure that all of my hyperlinks/cross references are intact. This is to ensure that I didn't accidentally link to a chapter from a different project. In other words, I need to make sure that my final PDF contains both the source and the destination.
    Does anyone know where I can find a script like this?
    Thanks,
    Kelly Vaughn

    A script can't do that. Maybe a plugin.

  • I need an app that will play one song from a list then pause

    I currently use a DJ style CD player to play backing tracks for the trio that I play with. The CD player has a "single" button that when you engage it will only play one song from the CD and then stop/pause. I need an app that will do the same thing as it relates to a playlist. Any ideas?

    It isn't an answer to your actual question but it might help:
    Try creating a playlist in iTunes with that one song you need to be played. Start that playlist (ipod app) and you'll see that your ipad will only play that song.

  • IDCS6(MAC) 10.9.4 - a script that will make an anchored object and paste in clipboard contents

    I'm trying to create a script that will create an anchored object that will paste in clipboard contents.
    So far I have:
    var frameRef = app.selection[0];
        var parentObj = frameRef.insertionPoints.item(0);
        var anchorFrame = parentObj.rectangles.add();
    And this works fine, creating an inline object, that can further be defined (with anchor point settings etc).
    However, it is when I go to use app.paste() or app.pasteInto() that all hell breaks loose.
    The line of code I added was:
    anchorFrame.content = app.pasteInto();
    and the error I get is:
    What am I doing incorrectly?
    Colin

    @Colin – For the paste command you like to use, you have to:
    1. First select an object, in your case the added rectangle object
    2. Then use the pasteInto() method from the app object
    3. There is no content property for a rectangle object
    Watch out what is selected after you added the rectangle.
    What you have is a selection of the text frame when you start your code in line one.
    Adding a rectangle will not change that selection.
    The following code will do the job.
    However, if you use pasteInto() the pasted objects could be only partly visible inside the frame.
    Depends on the size and position of the added rectangle relative to the original copied page items.
    Make sure that you give the rectangle a proper size after or while you are adding it:
    var frameRef = app.selection[0];
    var parentObj = frameRef.insertionPoints.item(0);
    //Will add a rectangle sized 40 x 40 mm
    var anchorFrame = parentObj.rectangles.add({geometricBounds:[0,0,"40mm","40mm"]});
    app.select(null); //Optional
    app.select(anchorFrame);
    app.pasteInto();
    Uwe

  • I need a programme that will be able to download my upgrade for my Parrot MKi9100-7.plf file

    I need a programme that will be able to download my upgrade for my Parrot MKi9100-7.plf file can anyone help?

    According to the Parrot Support site:
    "The Parrot Software Update Tool is only available for Windows."
    So you would need to install Windows on your iMac, first, in order to download the file.  Your Mac's OS X cannot read Windows based files.

Maybe you are looking for