Saving documents via Scripts: Get current file name and set save path/file type

I am writing a script that will:
-Make all layers invisible
-Make a layer named "background" visible
-Delete all the invisible layers
-Save the docment as an EPS file (leaving the original document untouched)
I am new to scripts and so have based my script by copying code from other scripts.
Here is my code:
var doc = app.activeDocument;
var name = doc.name;
var hide = function (){ // hide all layers (based on http://forums.adobe.com/thread/644267)
     var L=doc.layers.length;
     for (j=0;j<L;j++){  doc.layers[j].visible=false; }
hide();
// loop through all layers
for (var i = 0; i < doc.layers.length; i++) {
              // Create the illusrtratorSaveOptions object to set the AI options
    var saveOpts = new IllustratorSaveOptions();
    // Setting IllustratorSaveOptions properties.
    saveOpts.embedLinkedFiles = true;
    saveOpts.fontSubsetThreshold = 0.0
    saveOpts.pdfCompatible = true
//Set up Variable to access layer name
          var currentLayer = app.activeDocument.layers[i];
// Loop through the layers and make the back ground layer visible
          if (currentLayer.name == "Background") {
                    docName = name + currentLayer.name+".eps";
                    currentLayer.visible = true;
// Delete Invisible Layers (based on http://www.cartotalk.com/index.php?showtopic=7491)
var myDoc=app.activeDocument;
var layerCount=myDoc.layers.length;
for (var ii = layerCount - 1; ii >= 0; ii--) {
    var currentLayer = myDoc.layers[ii];
    currentLayer.locked = false;
    var subCount = currentLayer.layers.length;
    for (var ss =subCount -1; ss >= 0; ss--){
        var subLayer = currentLayer.layers[ss];
        subLayer.locked = false;
        if (subLayer.visible == false){
            subLayer.visible = true;
            subLayer.remove();
    if (currentLayer.visible == false){
        currentLayer.visible = true;
        currentLayer.remove();
// Save Out Document with New Name
var saveName = new File ( doc.path + "/" + docName );
doc.saveAs( saveName, saveOpts );
Everything works fine except:
1) It saves the document with the name AdobeIllustratorBackground as opposed to the name of the document
Also, I am not sure how to tell the script to save as EPS and to specify the save location.
Could some one give me some pointers?          Thanks!

Thanks! I changed my code to this:
var title = doc.name;
var title = title.substring(0, title.length - 3);
And it now works! (The substring thing removes the .ai extenion).
However, how do I get it to save it as an EPS? (I found this script that  saves as PNG, but I am not sure how to adapt it to EPS).
Also, how do I set the file output path?
Thanks for any help that can be offered.

Similar Messages

  • Script to create directory based on current file name and then save the file in that directory

    Hi all,
    I have a need save all my projects in a directory using the name of the main image I am working on.
    Manually these are the steps I used:
    Save As.
    Copy ( press command-c <== the filename is highlighted by default so all I have to do is )
    New Folder ( press the new folder button. Brings up a dialog box)
    Paste ( press command-v. <== Pastes the file name into the "New Folder" dialog box.)
    Save ( press thre save button. Saves the files into the new folder )
    Save As.
    Change format to JPG
    Save
    Change image quality to 12
    I want to assign these actions to a key
    Recording these steps and playing them back does not give me the results I need, snce the original name is hard-coded in the actionlist that was recorded
    What should I be doing instead ?
    Thanks in advance !

    You don’t mention which format the original file is (and figuring that and its current settings out seems too much of a hassle to me) so this would only save the jpgs into the folder (and create one if it does not exist).
    If you want to give it a try, paste the following text into a new file in ExtendScript Toolkit (part of Photoshop’s installation, Applications/Utilities/Adobe Utilities/ExtendScript Toolkit CS4 or /Applications/Utilities/Adobe Utilities-CS5/ExtendScript Toolkit CS5) and save it as a jsx-file into Photoshop’s Presets/Scripts-folder.
    After restarting Photoshop the Script should be available under File > Scripts and can be assigned a Keyboard Shortcut directly, recorded into an Action, (in CS4 and CS5) be used in a Configurator-Panel or started from ExtendScript Toolkit directly.
    // saves jpg into folder of file’s name next to file;
    // be advised: this  overwrites existing jpgs of the same name without prompting;
    // thanks to xbytor;
    // 2012, use it at your own risk;
    #target photoshop;
    if (app.documents.length > 0) {
    var thedoc = app.activeDocument;
    // getting the name and location;
    var docName = thedoc.name;
    if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
    else {var basename = docName};
    // getting the location, if unsaved save to desktop;
    try {var docPath = thedoc.path}
    catch (e) {var docPath = "~/Desktop"};
    // create folder if it does not exist;
    var folderString = docPath+"/"+basename;
    if (Folder(folderString).exists == false) {new Folder(folderString).create()};
    // jpg options;
    var jpegOptions = new JPEGSaveOptions();
    jpegOptions.quality = 12;
    jpegOptions.embedColorProfile = true;
    jpegOptions.matte = MatteType.NONE;
    //save jpg as a copy:
    thedoc.saveAs((new File(folderString+"/"+basename+".jpg")),jpegOptions,true);

  • How to get file name and set it as static text in a dialog

    Hi,
    I m new to InDesign Programming.
    I have a menu that creates a dialog with different controls in it.
    The dialog will appear only if there is an open file. I need to display the name of the open file as a static text in the dialog. I know to get the name of the current file but don't know how to pass this each time the dialog is opened.
    Can someone help me in doing this?
    I m using InDesign CS3 in MAC OS.
    Thank You.

    those are the methods, but you can't use getCharacterEncoding(), actually, cuz it seems it's not necessarily filled in.. or at least that might be on some servers only, like Tomcat 4. As for encodings, you need to do a search for character encoding names and use the appropriate one.

  • Need to get file name and directory back from file adapter - WRITE

    I am using the file adapter to write a file. I want to log the file name of the file we just created. Since we use a precise timestamp in the file name, I can't accurately guess.
    I have an invoke in my BPEL process to the file adapter. My first try was to assign the jca.file.FileName property to a variable, but it never comes back. I looked around and saw plenty of ways to SET the file name for a write and GET the file name for a read, but no GET file name for WRITE.
    Anyone have a solution?
    Thanks in advance!

    I think I got your point... You can tell FileAdapter the filename to write, but if you don't then FileAdapter can not tell you the filename that it wrote... I think it is pretty possible Oracle didn't implement the latter, as the write operation is probably asynchronous and the filename is calculated later on...
    If what you want is just log, you may achieve your requirement by increasing verbosity on Adapter logs... Have a look at the link bellow...
    http://docs.oracle.com/cd/E15586_01/integration.1111/e10226/ad_mon.htm#CJHHBBID
    Otherwise, the solution for you will be to calculate filename yourself, and that will be a little bit of reinventing the wheel... But at least you will know the filename...
    Cheers,
    Vlad

  • Adding file name and file full path to a page

    Hi all I'm new to scripting
    What I want to do and don't know how to go about it is to run a script that collects the saved file name
    and the full path where the file is saved on the network and displays it on my document
    If any one has done something similar or if some one can help me create it it would be appreciated
    Thanks Gabriel

    var idoc = app.activeDocument;
    var itext = idoc.textFrames.add();
    var file = idoc.fullName;
    itext.contents = file.fsName;

  • Pdf portfolio source file name and date in file details

    Is it possible to import the source file name and extension as well as the source file created date in the portfolio file details?  Need to document source to portfolio in working with 3rd parties that will only have the original source.  Need to document what was converted into pdf as not all files in a directory will successfully convert to pdf.  Sometimes need to convert 100's of files.  Manual entry is inefficient.  the file names and modified dates are displayed on the Combine Files dialog.  is there a way to capture the detail on that page?

    I don't need the detail of when the pdf was added to the portfolio.  I
    need know which dwg or jpg or word file was converted and the original
    created date of that file for control of information.
    That is impossible; sorry. For some *very specific* types of conversion to PDF the pdfx:SourceModified XMP tag will be set to show the last-modification date of the source file (for example DOCX files converted using MS Word), but there will never be a human-readable record of the source filename or its creation date unless you have manually added them as document XMP properties after conversion (this is what the "Custom Properties" dialog is for). To embed source data automatically would raise no end of privacy and security problems for customers, who most certainly do NOT want their recipients seeing details of internal documents.
    Without writing a plugin there's no access to the internal workflow of the Combine Files dialog, so you cannot use a script to read the names and dates of the files *before* conversion and store them automatically in the new PDF Portfolio's Fields array.

  • How to get uploaded file name and path in BefExportToDat event script

    I would like to get hold of the uploaded file name and full path in the event script "BefExportToDat", as I need to extract values from particular fields. However I have not yet found a way to do this.
    - The input variable "strFile" returns the .Dat file path in the Outbox, to which it is about to export the data. This is no use to me.
    - The API variable RES.PstrFilename is returning nothing
    I am using RES.PstrFilename in the "BefFileImport" event script in a different FDM application and it works fine, however I need to find a way to get this to work in the "BefExportToDat" event script.
    Please let me know how this might be achieved.

    I am looking through the API calls in FDM Workbench, but cannot see the table (tPOVPartitions) you mentioned listed. Is this the correct name? And do I just use the function listed in the object browser to run the query?
    Furthermore (going back to my initial thoughts of using strFile), it appears that although the variable contains the .Dat filename and path, the actual file is non-existent when "BefExportToDat" is executed:
    Error:
    Error: Export failed.
    Detail: File not found.
    This would make sense, but it does make the variable "strFile" a little pointless since one cannot make use of the file in this particular event script. Do you please have any thoughts on this?

  • Newbie - Dreamweaver CC 2014 - Document Scan - Get Save Path/File

    Hi, 
      I've been a programmer for a long time but have done very little web development. Last time I touched dreamweaver has to be 10 years ago. A company I'm working with is developing a web front end for their system. In their existing system, they are able to scan a document by pressing a button in the application. The button push scans the document and open Acrobat Pro. When the user saves the PDF, they are able to get the path where the user saved the file as well as the file name and then they store that information in the DB of previously mentioned system. From the application they are hitting a TWAIN driver to invoke the scanning (if I understood correctly). The scanner I saw this done with is an EPSON GT-S50 and I believe they are programmatically reading the registry to get the last 15 files that were saved and determining the path and file name from there.
    Since they are now developing a web front end over the existing business logic, there are some things they have asked me to figure out. The first of which is how to duplicate what I mentioned above in a web front end. That being said, here's what I need to do:
    - Add a button labeled "Scan" to a web page with Dreamweaver that will invoke the scan process of the EPSON Scanner.
    - Have that scanned document open in Acrobat.
    - On save of the document in Acrobat, I need to get the path and file.
    - Add a button to view the file labeled "View".
    - On select of the "View button", I need to display the PDF on the same web page.
    I've done a bunch of reading so far and I haven't quite found what I need. If you can help point me in the right direction or have done something similar or even if you just want to offer moral support (haha) please let me know. I'll respond as quickly as possible to additional questions, I need to move on this...
    Thanks,
    Rob

    Hi Nancy,
    Thank you for responding. I guess the environment would be helpful.. (Sorry) . The web front in will be on servers in one of the major clouds (AWS/Rackspace/etc) and the DB's will be on other servers in the cloud while the servers will be at the customer's offices. So yeah, it is complicated. What I'm trying to come up with is  way to do it without tying the end customer to have to marry their network to the cloud network or forcing them to use RDP or Citrix etc.. Trying to come up with the most flexible option. One other thing they are shooting for is mobile compatibility. I just started working on this with them, I wasn't involved in the meetings along the way...
    Thanks,
    Rob

  • How to find a text in the Frame maker document via script?

    How to find a particular text in the Frame maker document via script?

    johnsyns wrote:
    Why it doesn't work for the other days? When i tried to change the days other than wednesday. it return nothing.
    Reason why Justin's code does not work for other days is date format mask DAY returns day blank padded to 9 characters which is the longest day name which, yes you guessed right, is WEDNESDAY. You either need to blank pad or use format modifier FM:
    SQL> select *
      2    from (SELECT TO_DATE(SYSDATE+ROWNUM, 'DD-MON-YY') dt
      3            FROM DUAL CONNECT BY ROWNUM <= 27)
      4  WHERE TO_CHAR(dt,'DAY') = 'TUESDAY'
      5  /
    no rows selected
    SQL> select *
      2    from (SELECT TO_DATE(SYSDATE+ROWNUM, 'DD-MON-YY') dt
      3            FROM DUAL CONNECT BY ROWNUM <= 27)
      4  WHERE TO_CHAR(dt,'DAY') = 'TUESDAY  '
      5  /
    DT
    07-APR-09
    14-APR-09
    21-APR-09
    28-APR-09
    SQL> select *
      2    from (SELECT TO_DATE(SYSDATE+ROWNUM, 'DD-MON-YY') dt
      3            FROM DUAL CONNECT BY ROWNUM <= 27)
      4  WHERE TO_CHAR(dt,'FMDAY') = 'TUESDAY'
      5  /
    DT
    07-APR-09
    14-APR-09
    21-APR-09
    28-APR-09
    SQL> SY.

  • Problem with getting the file name and type from OAMessageFileUploadBean

    Hi Tapash,
    I am trying the code below to get the file name and mime type from OAMessageFileUploadBean,
    DataObject fileUploadData = (DataObject)pageContext.getNamedDataObject("Documents");
    String uFileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
    String contentType = fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
    But this piece of code gives errors saying that selectValue selectValue(null, java.lang.String) not found in class oracle.svc.DataObject
    Any ideas? why this code is giving error?
    Can i handle the event of browse button for OAMessageFileUploadBean?
    Regards,
    Nagesh Manda.

    Try using class oracle.cabo.ui.data.DataObject
    --Shiv                                                                                                                                                                                                       

  • I can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name

    can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name. My original external has an error and needs to be reformatted but I dont want to lose this informations its my entire Itunes library.

    Sounds like the source drive is formatted as case sensitive and the destination drive is not. The preferred format for OS X is case insensitive unless there is a compelling reason to go case sensitive.
    Why can't you change the filename? Is it because the source drive is having problems?  If so is this happening with only one or two or a few files? If so the best thing would be to copy those over individually and then rename them on the destination drive.
    If it is more then you can do manually and you can't change the name on the source you will have to reformat the destination as case sensitive.
    Btw this group is for discussion of the Support Communities itself, you;d do better posting to Lion group. I'll see if a host will move it.

  • Programaticly changing the (suggested only) file name in the save prompt when signing a document?

    When you sign a document in Adobe X (or XI), the system says it needs to save the file first.   Is there some way to change the (suggested only) file name to a different value for that save?
    Right now, people open a blank form - lets call it formX.pdf.   They fill it in and sign it.  The suggested file name for the save is FormX.pdf.   I can generate a unique file name which i'd like to put in place of the suggested default...

    AFAIK, you can't do it with code. Your best option might be to use a form field to show a message to the user when they sign the document with that information.

  • How to print file name and date on document

    How can we print the file name and date, like in the old days, on a document as a header or footer?

    Not the print dialog for iWork but in the app itself. Here is Pages:
    Regards,
    Colin R.

  • Adding the file name and path to a document

    Is there a way to automatically generate the file name and path (i.e. 'P:\ARF530\BACKGROUND\diagram.ai') to a document without having to copy and paste from the explorer window?

    Hi,
    So to select the directory, in the WHNE-BUTTON-PRESSED trigger write,
         :<block_name>.<path_item_name> := GET_FILE_NAME(' ', NULL, NULL, 'Choose any directory.', OPEN_FILE, FALSE);
         IF SUBSTR(:<block_name>.<path_item_name>, LENGTH(:<block_name>.<path_item_name>)) != '/' AND SUBSTR(:<block_name>.<path_item_name>, LENGTH(:<block_name>.<path_item_name>)) != '\' THEN
              :<block_name>.<path_item_name> := :<block_name>.<path_item_name> || '\';
         END IF;and to open the file, write,
    DECLARE
      FT_File  TEXT_IO.FILE_TYPE;
    BEGIN
      IF SUBSTR(:<block_name>.<path_item_name>, LENGTH(:<block_name>.<path_item_name>)) = '/' OR SUBSTR(:<block_name>.<path_item_name>, LENGTH(:<block_name>.<path_item_name>)) = '\' OR :<block_name>.<path_item_name> IS NULL THEN
           MESSAGE('Please Enter file name before continue');
           MESSAGE('Please Enter file name before continue');
           RAISE FORM_TRIGGER_FAILURE;
      END IF;
      FT_File := TEXT_IO.FOPEN(:<block_name>.<path_item_name>, 'w');
    END;Regards,
    Manu.
    If my response or the response of another was helpful or Correct, please mark it accordingly

  • Get file name and path from  adf inputFile

    Hi,
    I use adf's inputFile component. I need to get the file name and filePath. Does anyone knows how to do that?
    Thanks in advance

    You may bind the value to an UploadedFile object and get the name from this object.
    You may use a valueChangeListener backin bean method or a managed bean.
    Here the code i just write for something similar. Note that i'm not able to test it because of a bug in 10.1.3.1 with inputFile and web.xml parameters. I still waiting for the patch.
    public void uploadedFile(ValueChangeEvent valueChangeEvent) throws IOException,
    Exception {
    final int BUFFER = 2048;
    byte data[] = new byte[BUFFER];
    int currentByte;
    String fileName;
    UploadedFile uploadedFile =
    (UploadedFile)valueChangeEvent.getNewValue();
    if (uploadedFile != null) {
    String mimeType = uploadedFile.getContentType();
    if (mimeType == "application/x-zip-compressed") {
    // get the uploaded file as a zip file
    ZipFile zipFile = new ZipFile(uploadedFile.getFilename());
    // verify the zip archive contains only one entry
    if (zipFile.size() != 1) {
    FacesContext context =
    FacesContext.getCurrentInstance();
    ResourceBundle errorMessage =
    ResourceBundle.getBundle(context.getApplication().getMessageBundle());
    Exception ZipFileContentException =
    new Exception(errorMessage.getString("error.fileUpload.zipFileContent.moreThanOneEntry").replace("{0}",
    String.valueOf(zipFile.size())));
    throw ZipFileContentException;
    // get the entries in the zip file even it is only one
    Enumeration zipFileEntries = zipFile.entries();
    // Process each entry
    while (zipFileEntries.hasMoreElements()) {
    // grab a zip file entry
    ZipEntry entry =
    (ZipEntry)zipFileEntries.nextElement();
    // check the entry is not a directory
    if (entry.isDirectory()) {
    Exception ZipFileContentException =
    new Exception(JSFUtils.getStringFromBundle("error.fileUpload.zipFileContent.isDirectoryInsteadFile"));
    throw ZipFileContentException;
    File destFile = new File(entry.getName());
    Magic magic = new Magic();
    // getMagicMatch accepts Files or byte[],
    // which is nice if you want to test streams
    MagicMatch match = magic.getMagicMatch(destFile, true);
    if (match.getMimeType() != "application/xml") {
    Exception ZipFileContentException =
    new Exception(JSFUtils.getStringFromBundle("error.fileUpload.isNotXMLFile").replace("{0}",
    match.getMimeType()));
    throw ZipFileContentException;
    //TODO get the repository directory from classification-param.xml
    BufferedInputStream is =
    new BufferedInputStream(zipFile.getInputStream(entry));
    FileOutputStream fos = new FileOutputStream(destFile);
    BufferedOutputStream dest =
    new BufferedOutputStream(fos, BUFFER);
    // read and write until last byte is encountered
    while ((currentByte = is.read(data, 0, BUFFER)) !=
    -1) {
    dest.write(data, 0, currentByte);
    dest.flush();
    dest.close();
    is.close();
    zipFile.close();
    } else if (mimeType == "application/xml") {
    String currentEntry = uploadedFile.getFilename();
    File destFile = new File(currentEntry);
    BufferedInputStream is =
    new BufferedInputStream(uploadedFile.getInputStream());
    FileOutputStream fos = new FileOutputStream(destFile);
    BufferedOutputStream dest =
    new BufferedOutputStream(fos, BUFFER);
    // read and write until last byte is encountered
    while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
    dest.write(data, 0, currentByte);
    dest.flush();
    dest.close();
    is.close();
    } else {
    Exception ZipFileContentException =
    new Exception(JSFUtils.getStringFromBundle("error.fileUpload.isNotXMLFile").replace("{0}",
    mimeType));
    throw ZipFileContentException;
    }

Maybe you are looking for

  • Another "my contacts & calendars won't sync" guy

    My iPhone was bogged down and doing some strange things so I decided I'd reset it in an attempt to refresh things. After resetting it, my contacts and calendars will not sync over the air with Mobile Me. (Mail and bookmarks are fine) I can switch the

  • OS X Mavericks Finder Bugs?

    Upon updating my iMac to OS X Mavericks I noticed that Cover Flow contained a few annoyances and I have yet to find any discussions about this particular one. I've always used Cover Flow since I migrated to Mac but this seems specific to Mavericks. E

  • Open Hub Destination - Hierarchies

    Hi all,    We have a Open Hub that is based on the InfoCube FGL_CIFRS ie FGL Transaction Figures.We are exporting the Infocube data on to a Flat File . This Cube is built on Infoobjects like 0GL_ACCOUNT, 0PROFIT_CTR etc.    We also have Individual Hi

  • Array in Map

    Is it possible to put an arry into a HashMap? Map paramMap=request.getParameterMap(); String[] Str = (String[]) paramMap.get("lang"); It does return a String[]. In the map the values are put in array form. I want to modify the value of "lang" in the

  • OSX 10.8.5 won't connect to Windows 2008 R2 NFS

    Hi We have about 25 Mac clients in our Microsoft Windows environment. OSX is bound to our single Active Directory domain and all our Windows server are 2008 R2. For several years we have been using SMB filesharing and connecting the Mac clients to ou