Getting the name of a chosen file in applescript
Question: I need my AppleScript to know the name of a file chosen by a user in a `choose
file` command. It sounds like it should be really simple, but I can't figure
out the answer. The script extracts the frames from a gif file and puts the
individual images in a folder inside the application's contents. It then
changes the desktop background rapidly to the images inside the folder, hence
giving you a gif for a wallpaper. However, I can't do this without knowing the
name of the chosen gif file, as I don't know the names of the images in the
folder. If there's some other easy way around this, that would be great too.
This is what I have so far:

    
    
    on delay duration
    set endTime to (current date) + duration
    repeat while (current date) is less than endTime
        tell AppleScript to delay duration
    end repeat
    end delay   
    set gifFiles to choose file of type "com.compuserve.gif" with prompt "Select GIF"
    set dest to quoted form of POSIX path of ((path to me as string) & "Contents:Resources:Gif")
    set pScript to quoted form of "from AppKit import NSApplication, NSImage, NSImageCurrentFrame, NSGIFFileType; import sys, os
    tName=os.path.basename(sys.argv[1])
    dir=sys.argv[2]
    app=NSApplication.sharedApplication() 
    img=NSImage.alloc().initWithContentsOfFile_(sys.argv[1])
    if img:
    gifRep=img.representations()[0]
     frames=gifRep.valueForProperty_('NSImageFrameCount')
     if frames:
         for i in range(frames.intValue()):
             gifRep.setProperty_withValue_(NSImageCurrentFrame, i)
             gifRep.representationUsingType_properties_(NSGIFFileType, None).writeToFile_atomically_(dir + tName + ' ' + str(i + 1).zfill(2) + '.gif', True)
         print (i + 1)"
    repeat with f in gifFiles
    set numberOfExtractedGIFs to (do shell script "/usr/bin/python -c " & pScript & " " & (quoted form of POSIX path of f) & " " & dest) as integer
    end repeat
    repeat
    set desktop_image to (path to me as string) & "Contents:Resources:Gif:"
    tell application "Finder" to set the desktop picture to desktop_image
    delay 0.05
    set desktop_image to (path to me as string) & "Contents:Resources:Gif:"
    tell application "Finder" to set the desktop picture to desktop_image
    delay 0.05
    set desktop_image to (path to me as string) & "Contents:Resources:Gif:"
    tell application "Finder" to set the desktop picture to desktop_image
    delay 0.05
    set desktop_image to (path to me as string) & "Contents:Resources:Gif:"
    tell application "Finder" to set the desktop picture to desktop_image
    delay 0.05
    set desktop_image to (path to me as string) & "Contents:Resources:Gif:"
    tell application "Finder" to set the desktop picture to desktop_image
    


Answer: You can get the name with `System Events`

    
    
    set gifFiles to choose file of type "com.compuserve.gif" with prompt "Select GIF"
    tell application "System Events" to set gifFileName to name of gifFiles
    

or with the `info for` command, although it's deprecated since years it's
still working even in El Capitan

    
    
    set gifFiles to choose file of type "com.compuserve.gif" with prompt "Select GIF"
    set gifFileName to name of (info for gifFiles)
    

Of course it's possible using the Finder but it's recommended to avoid
involving the Finder as much as possible

