Droplet - getting name of dropped file

This post does not need answering, as I have already solved the problem described. I have put it here in case it might help someone else save a bit of time. However, feel free to make comments and observations for further enlightenment of myself and others who are grappling with various aspects of AppleScript.
Recently, I decided to learn to use droplets and open handlers. In my first attempt, I set out to modify an existing script which prompted the user to choose a file which is then processed in various ways. My aim was to drop the file on the new droplet version of the script, with the droplet identifying the file automatically, and have it run as before from there onwards. So far, through trial and error and a fair bit of internet searching, I have been able to work out most things in a reasonably short time. One that took me a while involved getting the name of the file which is dropped onto the droplet - the file name could be anything, but the script needed its name for the various things which happen in the script.
I quickly discovered that a droplet can quite happily and easily give a list of the names of files inside a folder which is dropped onto it. When it comes to just one single file, it took a bit of work.
I started off with something like this (with a few variations):
(the display dialog bit is there to show if I got exactly what I wanted - it's not necessary for the correct running of the droplet, but droplets don't have "Result" and "Event Log" available for seeing what's happening)
+on open Dropped_File+
+tell application "Finder"+
+set NameOfFile to name of Dropped_File+
+display dialog NameOfFile+
+end tell+
+end open+
There was usually an error message such as: Can't get name of {alias "Macintosh HD:Users:username:Desktop:filename.txt"}, or another one about not being able to make the acquired information into the right data type. Generally I was getting the complete pathway of the file, but couldn't separate out what I wanted from the rest of it.
As part of my looking for a solution, I tried duplicating the file and getting the name of the copy. Success, in the sense that I could get the name of the copy.
+on open Dropped_File+
+tell application "Finder"+
+set CopyOfFIle to duplicate Dropped_File to desktop+
+set NameOfCopyOfFIle to name of CopyOfFIle+
+display dialog NameOfCopyOfFIle+
+end tell+
+end open+
After more experimentation I found the "info for" command (in StandardAdditions), and ended up with the following successful droplet:
+on open Dropped_File+
+tell application "Finder"+
+set NameOfFile to (name of (info for Dropped_File))+
+display dialog NameOfFile+
+end tell+
+end open+
I hope this saves somebody some time. About a third of my scripting attempts are usually assisted unknowingly by someone else who has been trying something similar and, having succeeded, posted their results online for others to benefit from.

Hi Pierre,
I tested both at the same time with the following code:
+on open Dropped_File+
+tell application "Finder"+
+set Name1OfFile to name of item (item 1 of Dropped_File as alias)+
+display dialog Name1OfFile+
+set Name2OfFile to name of (item 1 of Dropped_File as alias)+
+display dialog Name2OfFile+
+end tell+
+end open+
Both versions gave the desired result - just the name of the file - whereas when I had tried using "as alias" (obviously not in the same place and not using "item 1 of") I had received error messages. From memory, I think I had tried "name of (item Dropped_File) as alias".
I "fiddled" with your suggestion a little, and found that the following (omitting the "item" and "item 1 of") also works:
+on open Dropped_File+
+tell application "Finder"+
+set Name1OfFile to name of item (Dropped_File as alias)+
+display dialog Name1OfFile+
+set Name2OfFile to name of (Dropped_File as alias)+
+display dialog Name2OfFile+
+end tell+
+end open+
It looks the correct placement and usage of "as alias" did the trick.
Thank you very much for taking the time to examine the problem and come up with a solution which should work equally well under both System 10.4 and 10.5.
Message was edited by: Steven Jones

Similar Messages

  • Getting names of all files in a directory.

    import java.io.*;
    import java.util.*;
    public class dir{
         public static void main(String args[]) throws IOException{
              //BufferedReader in = new BufferedReader(new FileReader(args[0]));
              PrintWriter out = new PrintWriter(new FileWriter("dir.txt"));
              File file = new File(args[0]);
              //FileFilter filefilter = "log";
              Vector x = new Vector();
              int vlength;
              x = getDirectoryContent(file);//,filefilter);
              vlength = x.size();
              for(int i=0;i<x.size();i++){
                   out.println(x.elementAt(i));
              out.close();
         public static Vector getDirectoryContent(File file){//, FileFilter fileFilter){
              Vector v= new Vector();
              if (file.isDirectory()) {
                   File[] content = file.listFiles();//fileFilter);
                   for (int i=0; i<content.length; i++){
                        v.addElement(content);
                   }//for
              }//is directory
              return v;
         }//getDirectoryContent
    That is the code that I am using, what I am trying to do with it is read all the files in a directory. So I can open them and calculate all the data in all of the files at the same time.
    These are the file names that are in the directory when I run the program.
    L0519013.log
    L0331001.log
    I have the code out put the file names in a file called dir.txt
    after running the program this is what I get in the output file.
    [Ljava.io.File;@70ccc4b2
    [Ljava.io.File;@70ccc4b2
    [Ljava.io.File;@70ccc4b2
    Any clue waht this means?
    also I am passing in the director as args[0]

    if possible as well...
    I could not get the FileFilter to work, could not get the syntax down to get it to work when I was initializing it so for the moment it is remed out. all files in the given directory will be of type .log so there really is no need for the FileFilter. But any help on how to include that in the code would be greatly helpful.
    Thankxs
    Korbin

  • Getting name of jsp file.

    i have a jsp file calling another jsp file. how do i get the filename of the first jsp file? It has to be obtained at runtime.

    Ive been looking into the same problem, whilst it is possible to get the path / current working directory, I have not found a way to get the filename.
    I think you are going to have to pass the name as a parameter from the first page.

  • How to get name of batch file/shell script that starts program?

    I don't think there's a way to do it, but I'm asking the question anyway...
    of course, the startup script could pass its name as a parameter to the Java program, but I was wondering if the information could be determined "directly," via Java code. The idea is to allow your Java program to modify the startup configuration specified by your startup shell script.
    For example, a "startup configuration" menu item would pop up a dialog box that would display- and allow you to change- the startup parameters, and then let you write the changes back to the script file.

    There are always some ways to do things.
    I guess for your case, you need to go through JNI and have a native program to back track the Process ID of who started who. Never done that but I guess should work.
    But a more natural way to do this is to have your startup configuration stored in an xml file or a properties file inside your classpath.
    --lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Get name of a file

    I have a full filename information (directory + file extension) and I would like to have only the filename without directory without extension. Is is possible with LabWindows
    For instance,
    I have c:\test\text1.txt and I would have text1
    Thanks 

    To exclude the extension you can do the following:
    if ((nc = FindPattern (FileName, 0, -1, ".", 0, 0)) > 0) FileName[nc] = 0;
    FindPattern is part of the Formatting and I/O Library
    Edit: written while Wolfgang was giving the same response 
    Message Edited by Roberto Bozzolo on 06-07-2010 12:33 PM
    Message Edited by Roberto Bozzolo on 06-07-2010 12:34 PM
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Trying to drop files onto a droplet that is already in progress with another file.

    I'm trying to find a way to drop a file on a droplet and before the action of that droplet finishes,  drop another file on the droplet and have a queue or some other way of photoshop recognizing and processing the second request once the first has finished.  Currently PS CC 2014 just ignores the second file.  I think automator must have a way but have been messing around to no avail.

    Ah, I see now what you mean, Marc but I don't know an answer.
    Maybe you could try and see what happens if you make two or more droplets
    (with identical contents but a different name - so you can put them in the
    same place). Not sure if this is even possible but maybe worth trying...
    Met vriendelijke groeten,
    Ronald
    2015-03-17 21:16 GMT+01:00 marcimpact <[email protected]>:
          Adobe Community <https://forums.adobe.com/?et=watches.email.thread>     Trying
    to drop files onto a droplet that is already in progress with another file.
    reply from marcimpact
    <https://forums.adobe.com/people/marcimpact?et=watches.email.thread> in *Photoshop
    General Discussion* - View the full discussion
    <https://forums.adobe.com/message/7309203?et=watches.email.thread#7309203>

  • I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings?

    I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings? Please help. Thanks.

    You should have asked this before you tried: Changing username or short name- User Account and Short Name- OS X- How to change user account name or home directory name.

  • 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.

  • When trying to 'Consolidate Files' via iTunes I get the message "Copying files failed. The name was invalid or too long."

    I am trying to copy my entire iTunes library and everything in it from my PC Desktop to my PC Laptop using the "External Drive" method as shown on the Apple website. On Part 1 (5) I am told to consolidate files. When attempting to do this I get the message "Copying files failed. The file name was invalid or too long."
    How do I resolve this?

    I have just been having this problem and it has been driving me mad.   The error message doesn't tell you which file is causing the problem so you can't fix it and it leaves your libray in a state of limbo with some files copied into the new location and some in the old location.  After many hours I found a surprisingly quick and simple solution.
    1) in iTune create a smart play list that includes everything that was added before tomorrows date.  This will include everything.
    2) Right click this playlist and export it as a text file to produce a tab delimited file.
    3) Import this into a spread sheet, or just view it in a text editor with line wrap turned off.  What you are interested in is the last column (or end of the line in a text editor).  This gives you the path of the file associated with each entry in the library. 
    The path of the files that have already been copied successfully will start with the new location for your media files you specified.  Scroll thru the rows until you get a blank path.  If you start getting paths starting with the old Media file location then you went to far and start scrolling back.
    The row with the blank path was the file that failed.  Move back to the start of the row to find out more about it.  In my case it was a podcast with a very long name. I just deleted that podcast from iTunes.
    4) Restart the consolidation by choosing File, Library as you did before and the process starts again where it left off.
    5) If it fails again on another file just repeat the process

  • I am using itunes 10 and trying to consolidate my files.  I keep getting the error "Copying files failed.  The file name was invalid or too long".  How can I indentify what file is causing this problem or resolve this issue?

    I am using itunes 10 and trying to consolidate my files.  I keep getting the error "Copying files failed.  The file name was invalid or too long".  How can I indentify what file is causing this problem or resolve this issue?

    BUMP
    Yes, I just get that message. I don't see how I could investigate this problem.
    I didn't mention that this happened when I was consolidating my library, not copying files to another computer.
    In other words, I'm using a "normal" itunes procedure, itunes won't complete it, and won't tell me exactly why or how to figure out how to fix it...
    Is there at least some easy way to tell which files were successfully copied to my itunes music folder so I can work on moving the uncopied files?
    Can anybody help me?

  • Need of a Webservice to get the name of the file in a Folder

    Hi All,
    I am in need of a Web service which should get the name of the file in a folder.
    Note :  Folder is created in the MOSS server.
    Thanks.

    Just to add, Mac in intergrated into AD and all I need is help in creating the script
    Thanks

  • Getting the local full path name of a file from an item File Browser

    Hi all,
    I would like to get the local full path name, of a file selected from an item 'File browser'.
    I see in wwv_flow_files the column 'name', but actually it's a kind of id like 'F1542335/myFile.gif' for example.
    What i want is the local path of this file ("C:\Documents and Settings\All Users\....\myFile.gif").
    I hope this is possible??
    Anyway, thanks all for reading.
    Ludo

    Hello, thank you for the answer.
    Please understand that I searched before posting, and not ony 15 min.
    What i mean is that the value of a File Browser in an Apex applocation is something like 'F1542335/myFile.gif', but what I need is the local path location.
    And 'F1542335/' is not the local path location, i can't use it. Or maybe there is a way to convert it in a proper path name, such as "C:\Documents and Settings\....", but I don't think so.
    So my question is : how to get the local path name of a file in Apex?
    I'll answer if I find some good things.
    Thanks
    Ludo
    Edited by: user12945874 on 06-avr.-2010 3:59

  • How to get the pull path name from a file upload window

    Hello everyone!
    I have encountered the following problem with the following JSP code:
    <form method="post" action="filename.jsp">
    Upload JAVA program:
    <input type=file size=20 name="fname" accept="java">
    <input type=submit value="go">
    </form>
    <%
    String s = "";
    if (request.getParameter("fname") != null)
    s = request.getParameter("fname")
    %>
    The value of s is alway the filename. However I want to get the full path in addition to the filename, so that I can read the file. Does anyone know how to get the pull name of the file?
    thanks a lot in advance,

    Dear Sir,
    thanks a lot for your reply. Please let me explain what I intended to do: I want to upload a file from the local machine and then read the content of the file. Therefore I need to the fullpath of the filename like /var/local/file.java instead of file.java. The latter is what I got.
    The problem I have with your code is that the function like "request.getServerScheme()" is not recognized. Maybe is it because I didn't install servelet package? I only installed javax package btw. Also my application runns on Tomcat server if this could give you some information. The error message I had is as follows:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:133: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    url = request.getServerScheme()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:136: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    + ((("http".equals(request.getServerScheme()) && request.getServerPort() != 80)
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:137: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    ||("https".equals(request.getServerScheme()) && request.getServerPort() != 443))
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:139: cannot resolve symbol
    symbol : method getServletConfig ()
    location: interface javax.servlet.http.HttpServletRequest
    + "/" + request.getServletConfig().getServletName()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:140: cannot resolve symbol
    symbol : variable path
    location: class org.apache.jsp.addExercise_jsp
    + "/" + path
    ^
    5 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

  • How to get the full path name of a file

    Hey everybody, I'm new here and in Java.
    so I will explain my question by giving an example:
    I want to send file from the Desktop by the "Send to" on the popup menu to my program.
    I want to know how can I read the full path name and the file name, and show it on my text box.
    Thanx alot

    If this is a client side application then I'd say look into drag-n-drop tutorials.
    i.e. drag file to your application, action listener fires, create File object giving you full name and path of users action.
    If this is a web application then look into the "multipart/form-data" content type specifications on how to upload files.
    i.e. user specifies file from <input type='file' ... /> type, submits, servlet receives data and recreates file locally on application server side.
    If you are thinking that all you need to send a file to a program is the full path and name in a textbox its a little bit more complicated then that.
    Good luck, hope that helps!

  • How to get immediate parent directory name of a file

    Hi,
    I have file Object that points to a file. I want to know how I can get just the name of the parent immediate to the file For example, if the path of this file is, c:\\ProgramFiles\first\second\third\myFile.txt
    In the above, how can I obtain the last directory in which myFile.txt resides ?
    Thanks
    Sangeetha

    File myFile = new File("c:\\ProgramFiles\\first\\second\\third\\myFile.txt");
    File parentFile = myFile.getParentFile();
    String parentDirectory = parentFile.getName();
    System.out.println("Parent directory is "+parentDirectory);Here's the explanation...
    1) New File is created
    2) File.getParentFile returns the immediate parent of the current File, which happens to be a directory.
    3) File.getName() returns the name of the File, without the entire directory structure.
    Hope this helps :)
    Simon

Maybe you are looking for

  • BIG problem with Mail after updating Mac OS X Leopard to 10.5.7

    Hi everyone, after updating OS X Leopard to 10.5.7, I noticed that all of my Mail accounts had disappeared. If I try to set them up again, Mail doesn't seem to be able to store them and after quitting and re-launching, they're gone. This had never ha

  • Converted raw (or .dng) will not open in ACR?

    OK, now that I've gotten sort-of over the hurdle of synching all the pieces associated with a smart object, I've hit the NEXT hurdle (SOs appear to be the usual double-edged sword - kinda handy in a way but rife with pitfalls and hurdles)... I open a

  • Is copying songs one-way street

    I've had a 15GB iPod for a couple of years now and have always copied songs from computer to iPod. Recently bought a new computer and was trying to copy songs back from iPod to machine, but I can't figure it out. Is it a one-way street?

  • Downloaded adobe reader 8- being asked to purchase

    Please help. Just downloaded FREE Adobe Reader 8. Now when I click to view a pdf in an IE browser, I get an error "problem with adobe software" when I view the first page of the pdf. When I try to advance to the second page of the pdf, I get a window

  • Downloading updates problem 5800

    On my phone there is available update  Version No.60.0.003. When I start downloading the phone displays Processing for 3 secends and then stop and noting hapening. Please help