Check the file type after JavaScript File.openDialog ()...

So I am on Mac OS and want my script obviously cancel on the bottle of 'Cancel', but also check if the selected file is a PDF file. I had some success with the code below, but some PDF, I select get cancelled with this script. While they inspected, the FilePath.type property returns "?" for some PDF files - anyone know why?

var myFilePath = File.openDialog("Please choose a PDF file...", undefined, false);
if((myFilePath == "") || (myFilePath == null)){
    exit();
}
else if(myFilePath.type != "PDF "){
    alert("Please choose a PDF file!") ;
    exit();
}

I'm quite new to scripting. Thank you!

On Windows, all you can do is provide a file extension (the well-known "*.") PDF filter"), and it is wise to always add the catch-all" *. " ' * ' to 'all files '. In this way, a user can select a file, even if she has a bad job (and in this case, it is the responsibility of the user to ensure that the file is of the type expected nonetheless).

Under OSX, there are two options:

1. the file has the correct ' Creator/Type' metadata; and/or

2. the file has the correct file extension.

Historically, focused on the Macintosh OS used option #1 and software should not look at the actual file names. However, who soon became unfeasible when people tried to share files between Mac and (almost all) other systems. That lead to various tools to "attribute" Data Type/Creator of known file extensions, so they can be opened with the right software on Mac. Also the reverse that's happened; saving a file "without extension" on a Mac was not a problem, but to open it in Windows, you often had to add the right extension.

So, somewhere around one or two versions of the system there, Apple has decided to return to the old, trust "File Extension." But OSX still records the Type/Creator metadata for files created on your Mac. Control of the 'type' should work then - but the problem is, what happens if you got your file also? The extension may be correct, but if she has any type of file, your script won't see it.

Fortunately, the open a Mac OS x file dialogue box allows some pretty wicked customizations. Never forget a file filter, you can run a custom function which decides for each separate file and the folder should be adjustable or not. The function has access to all the file attributes. You can go up to check the name of the file and dismiss all files that contain a 'q', or the files are read-only, or that are smaller than 1 KB.

Check out this piece of code (I wrote it myself, but various tips and tricks have been played on this same forum):

if (File.fs == "Windows")
    pdfFile = Folder.myDocuments.openDlg( 'Load PDF document', "Adobe PDF:*.pdf,All files:*.*", false);
else
    pdfFile = Folder.myDocuments.openDlg( 'Load PDF document', function(file) { return file instanceof Folder || (!(file.hidden) && (file.name.match(/\.pdf$/i) || file.type == "PDF ")); }, false );

(I advise you to copy the fragment of Windows, just in case your script will ' world tour.)

Tags: InDesign

Similar Questions

  • After that the effects cannot continue: error when access to the files instead of inside "/ users/me/Library/Preferences/Adobe/After Effects / 13.8", if it please check the file permissions and try again.

    After that the effects cannot continue: error when access to the files instead of inside "/ users/me/Library/Preferences/Adobe/After Effects / 13.8", if it please check the file permissions and try again.

    [Fixed spelling - Mod]

    Go to the folder listed in the path and change the permissions to read/write. Do you know how? It is in the info file.

  • Check the file system on C or registry cannont load the hive!

    Ok... I have a Dell Vostro 1510... all of a sudden, I can't on this laptop!  I have Windows XP Professional.  It lights up when I choose to start windows... I am said to be:

    Checking file system on c:

    The type of the file system is NTFS.

    Volume label is System.

    Then, when it starts to run it says: CHKDSK checks the files (step 1 of 3)... it happens to 47% finished and that's all!  It won't do anything else, it just stops!

    If I have to cancel the verification file system I get this message:

    STOP: c0000218 {Registry file failure}

    The registry cannot load the hive (file):

    \SystemRoot\System32\Config\System

    or its log or alternation.

    It is damaged, missing, or not accessible in writing.

    I do not have the disks provided with the laptop or I will say that I can not find them... I read a lot of these forums but none I saw helps me!  Because I can not enter and try to run anything!

    Thanks for any help in advance!

    I see you mentioned do not have all the disks with the laptop and maybe it's that he came not with any, because the installation files are likely in a hidden partition.
    but try to borrow a winxp cd and boot with it.
    then in the window settings pitch repair to start the recovery console.
    then at the prompt of disk, run the following >:
     
    Chkdsk /r
    Chkdsk /f
     
    then exit, remove the cd and restart the computer.
     
    the above commands are redundant, but nothing wrong with double controls.
     
    In addition, if you receive a following error on boot sector, then run via the recovery console fixmbr.
     
     

    --
    DB·´¯'·.. ¸ ><)))º> --> sent via windows live mail

    .

    DB·´¯'·.. ¸ >-))) º > ·´¯'·.. ¸ >-))) º > share nirvana mann
  • Please give me the number of hash MD5 to check the file .iso from win7

    Please give me the number of hash MD5 to check the file in win7 because when I try to install win7 (after dload web) its saying some files are missing if please check the files and restart the installation process. so I need to check the file I downloaded is full or not

    Please send me the file md5 hash as soon as possible

    Windows 7 RC Build 7100 x 86
    File name: 7100.0.090421 - 1700_x86fre_client_en-us_Retail_Ultimate - GRC1CULFRER_EN_DVD.iso
    Size: 2.35 GB
    MD5 Hash: 8867C13330F56A93944BCD46DCD73590

    Windows 7 RC Build 7100 x 64
    File name: 7100.0.090421 - 1700_x64fre_client_en-us_Retail_Ultimate - GRC1CULFRER_EN_DVD.iso
    Size: 3.04 GB
    MD5 Hash: 98341AF35655137966E382C4FEAA282D

  • "Error when access to the files of preference... Please check the file permissions and try again.

    I tried installing After Effects test and received the error message:

    "After that the effects cannot continue: error when access to the files instead of inside" / users/Kelly/Library/Preferences/Adobe/After Effects / 13.5 ", please check the file permissions and try again. '"

    I'm unable to check file permissions because the file path does not exist.

    I'm on a 2013 15 "retina Macbook Pro running OSX 10.9.5

    Premiere Pro downloaded successfully. After effects will be not open and wont let me start a trial (he thinks I've already started?)

    Screen Shot 2015-08-19 at 13.48.27.png

    Thanks for any help that is going can offer!

    kbombcarpenter To access this file reference the steps mentioned on help below link, user library folder is hidden by default.

    Access the hidden user library files. Mac OS 10.7 and later versions

  • using the file.openDialog filter expression

    Read the PDF Adobe JavaScript. I can't understand how we can filter the files available in the File.openDialog range. I would like to have the limited choice of .csv files. I know that I have a different method depending on whether the user is on a mac or a PC.

    Understand the function of filter on OSX was not obvious to me too.  Available version of Adobe's JavaScript Tools Guide which has a real-world example of the filter function, then I found this thread which has a very good example of implementation.  Then there's the StackOverflow answer to a question I posted this topic.  Hope these references help.

  • Check the file size before downloading

    Hi there guys...

    I'm having a problem at the moment... How can I check the file size before being transmitted to the server?

    I was given a task to check if the file size limit is 500 KB and then block the download and warn the user.

    According to my colleague from work... This is not possible with Javascript or Ajax... is there another method I can use?

    kindly help... Thank you

    It is a good answer, but it is interesting to note that Flash Player is itself a control ActiveX (when run in IE). In short, you need something beyond code that runs directly in the browser to do this. It can be done with just HTML and JavaScript in a web page.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Fig Leaf Software is a small business Veteran - Owned (VOSB) on

    GSA Schedule and provides high caliber of the authorized seller

    instruction at our training centers, online, or on-site.

    Read this before posting:

    http://forums.Adobe.com/thread/607238

  • How to check the file for the virtual machine size Esxi shell

    Anyone who can tell me how to check the file for the virtual machine size Esxi Shell. I tried this command-h ls but does not work.

    Have you checked "ls-lh', it will provide information as the attached screenshot." "

  • Check the file if it is corrupt

    I have a problem with corrupted files.

    According to me, the PC was off, while labview written my txt file...

    is there a way to check if I have the file is corrupted?

    I insert a crc check.

    but the problem I had, that the user can type the file name and that no filtering of illegal characters are made. If labview could not save a file with non-compliant characters in the file name...

  • How to check the files of Microsoft to be legitimate?

    I have a Compaq Presario desktop computer comes with XP Media Center 2005.  It has been updated to SP3.

    Recently, I ran free TDSSKiller from Kaspersky Lab to check my PC for the DNSChanger Malware.  After executing TDSSKiller, he registered 6 files to be suspicious. Two are Microsoft files. The files and their paths are:

    (1) mhn.dll.  Path: C:\WINDOWS\System32\mhn.dll

    (2) mhndrv.sys.  Path: C:\WINDOWS\System32\DRIVERS\mhndrv.sys

    How to check that these files have not been modified by a virus?

    Thanks, Terry

    Scan the files with your antivirus application (which is...?)

    You can also download on Virus Total, as long as the file size is less than 32 MB.

    Total virus scan files downloaded with about 39 different tools antivirus and you provides reports:

    https://www.VirusTotal.com/about/credits/
    https://www.VirusTotal.com/about/
    https://www.VirusTotal.com/FAQ/

  • Computer froze while then restart using Yahoo, has started checking the files on the drive.

    Original title: is there a MicrosoftXP NTFS file system? If SO, is there a file 875?

    Working yahoo trying to open the file that was sent when the computer locked upand I had the switch works / stop. When I rebooted it came up on top of the page that opens, he Microsoft XP in the upper right corner with the logo but not color. She has also shown a verification program files on three washers on a message from a third party came this missing 875, after a short wait of the comuter open file. It is a real program under XP or is a person playing with the computer? I'm computer dumb and need all the help I can get.

    Hello

    It seems that the computer has started when you have turned on the computer running chkdsk.

    CHKDSK is a valid Microsoft XP program and it checks bad blocks on the disk.

    As Yahoo application was running at this time, the 875 file could be belongs to it & seems to be corrupted.

    For more information, refer to this link: How to make Windows XP disk error checking?

    I recommend you to reinstall the application that was running at this moment of time if they are not running properly.


    Reference:
    How do I change or remove a program in Windows XP?

    Hope the helps of information.

  • With the help of cgi. CONTENT_LENGTH to check the file size before cffile

    I'll set up a form that allows users to upload files to our site ftp on the web server. I want to restrict the total size of the file to say 50 megs so I use an if statement and cgi. CONTENT_LENGTH to check the size of the file. It seems that the check can be done once the file is downloaded to a temporary file which defeats the purpose to check the size if it's already there. In my tests it make take 15 minutes to discover that my 52 meg file exceeded my limit of 50 MB. Is it possible to do the checking of file size before you actually download the entire file?

    Right, with cffile, you need to download everything first.

    There is a Flash/CFforms elegant solution that will allow you to access BEFORE upload file size. See ASFusion.com:
    http://www.AsFusion.com/projects/FileExplorer/http :// www.asfusion.com/examples/item/file-u pload-with-coldfusion-flash-forms

  • Check the file size

    Hi all. Can someone help me how to check the size of a file using Oracle 10 g 2?

    Thank you.

    You can use UTL_FILE. FGETATTR.
    This procedure reads and returns the attributes of a file on disk.

    Syntax

    UTL_FILE. () FGETATTR
    location in VARCHAR2,
    name of file in VARCHAR2,
    There are BOOLEAN,
    file_length ON the NUMBER,
    blocksize OUT NUMBER);

    Parameters

    location: location of the directory of the source of the file, a view ALL_DIRECTORIES DIRECTORY_NAME (case sensitive).
    filename: the name of the file to examine.
    There are: a BOOLEAN to determine if the file exists.
    file_length: the length of the file in bytes. NULL if the file does not exist.
    block size: the size of block of system file in bytes. NULL if the file does not exist.

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14258/u_file.htm#i1003488

    More examples of UTL_FILE can be found here (among others):
    http://www.Oracle-base.com/articles/9i/UTL_FILERandomAccessOfFiles9i.php

  • Could not start the automatic updates. Get an error that Windows cannot check the updates, D0000034 after the failure of the Java updates

    OP: Action Center... PC problem: 1 important message

    After the failure of the attempt to install the JAVA update, I received this message from Action Center... Windows cannot check the updates. So I was taken to the dialog box and retried to check the updates of windows fails again with the code D0000034. Also did a system restore to the place before the installation of JAVA update attempt, but was no help. Can you help me?

    Hello Irfan,

    Thanks again for your response. Since your last I discovered through my system status (Control Panel), I wrote that my product ID and the Windows 7 activation status not available. So I followed instuctions to help and microsoft support to activate.  Yet once, I got the error code D0000034 as before with the problem of update. However, I was given the opportunity to phone, but received no phone #. I bought the DVD of Windows 7 and installed on the PC that was custom built for me.  On the site Web microsoft help and support, I was asked for the product ID, which according to them is a # 20 numbers.  Not the only one, I have is the product key which is one 25-alpha-numeric.  I tried to enter only and does not pass.  This is why I say that I can pay for help since I did not ' have the product ID.  Maybe it isn't your area of expertise, Irfan, but I was hoping... I re - install windows on last April when I got in trouble and probably did not re - activate? What do you think?  If you can get back on track, I would be very grateful and thank you once again to be a big help!

    wandrinstar

    Please ignore above request. I have since re-activated Windows and the problem was solved with technical assistance telephone and thank you again for your help, Irfan. Also thanks to all the people answering the phone at microsoft. The experience I had was really a pleasure. I wasn't expecting such an attitude courteous and professional.

    Keep up the good work,

    wandrinstar

  • Check the file types flat column list and column

    Hi guys!

    Is there an "easy way" to check if the source file names flat column and column types correspond to the types and the column name for the data store target?

    Kind regards

    PsmakR

    Hello

    Is there a way that I've used some time to validate if the data are under the target.

    Conditions:

    (1) the source file should have all the columns as "String".

    (2) all the column analyzed mapping has to go to the "staging area".

    How to: (average oracle)

    (1) create a database (by the ODI procedure) function as:

    create or replace function $ F _DATATYPE (pData in varchar2, pDatatype in varchar2, pFormat in varchar2)
    return varchar2 as

    date of $vdate;
    number of vNumber;

    BEGIN

    If pDatatype = ' then / * Date * /.

    $vdate: = to_date (pData, pFormat);

    elsif pDatatype = ' only then / * number * /.

    If pFormat is null then
    vNumber: = to_number (pData);
    on the other
    vNumber: = to_number (pData, pFormat);
    end if;

    end if;

    Returns "OK";

    EXCEPTION
    While OTHERS then
    return "KO."

    end of F$ _DATATYPE;

    (3) now, you can create a constraint to each column in the source you want to validate data as:

    = 'OK' F$ _DATATYPE(my_source_column, 'D', 'ddmmyyyy hh24:mi:ss') / * for a date as an example column * /.

    (4) drag / move the source (table model) data source in the package and a table of $ E with all errors will be created.

    This help you?

Maybe you are looking for

  • Neither 1764 and line scan.

    Hi all The support of smart camera OR 1764 1/2 and 1/4 scan modes. Is it possible to use the camera in linear scan mode - tell to use only one or a few lines of the CCD array? If so, what will do about it? Some special modules? If not, it could be im

  • cannot restore the system with the Vista recovery disc, computer stuck in step 3 of 3 loop

    Hi all My computer has been blocked in the formidable step 3 of 3 loop. I followed the advice of Mr. Murphy and created the Vista recovery disk. I loaded it and followed the instructions. Everything was fine. I chose a 5 days ago restore point, and i

  • Install Windows Mobile on WIndow 7

    Can I use Windows Mobile Device Center on Windows 7?  Should I use 6.1 or another?

  • How can I turn the WiFi off on my Gateway NV55C laptop?

    original title: where is the switch for wifi on windows 7? Hello! I use a Gateway NV55C laptop with windows 7 pre-installed. I had recently turned off the wifi card to see if I could increase the fo my laptop battery life. But now I can't find the bu

  • Change Date/Time (zone) on ACS5.1

    Would like to know where I can change the date/time (zone) within the ACS v5.1.  Change in the BIOS is not an option in area, just the time.  ACS then displays something completely different when starting.  Have not been able to find the settings for