Your best friend for file transfer.

Fetch application logoFetch

AppleScript: descriptor mismatch (22 posts)

This is an archived topic. The information in it is likely to be out-of-date and no longer applicable to current versions of Fetch.
  • Started 22 years ago by DougAdams
  • Latest reply 22 years ago from Jim Matthews
  • DougAdams Member

    I'm updating a script I used with Fetch 3.0.3 for 4.0.1 in OS X. But I'm getting a descriptor mismatch when I use a variable instead of a string when defining the initial directory in a make statement, like so:

    set ftpDir to "images"

    make new transfer window at beginning with properties {hostname:"myhost", userid:"myID", password:"myPW", initial directory:ftpDir}

    However, if I hardcode the initial directory as text, ie: "images" instead of ftpDir, it works fine. I don't want to hardcode tho, because the script determines the initial directory based on a parse of the document's filepath on my end, which can vary depending on where the doc I'm sending is located.

    The snippet above worked fine in Fetch 3.0.3. Any ideas?

    Posted 22 years ago #

  • Jim Matthews Administrator

    Hmm, I'm not able to reproduce that problem (it works fine for me). Could you post the contents of the Event Log window after trying to run a script with that statement?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • DougAdams Member

    Hello,

    Here is data from Event Log:

    tell application "Tex-Edit Plus"
    get file of window 1
    --> alias "OS X:W E B Stuff:te:fbakokay.html"
    end tell

    tell Application "Fetch 4.0.1"
    activate
    make new transfer window at beginning with properties {hostname:"somehostname", userid:"someID", password:"*****", initial directory:"te"}
    --> Fetch 4.0.1 got an error: A descriptor type mismatch occurred.

    What you don't see is how the "te" was arrived at, but you can see that "te" is the parent folder of the document I wish to send. Also, the variable ftpDir is declared as global at the top of the script so it can be seen in both tells.
    Any help is greatly appreciated.

    Posted 22 years ago #

  • DougAdams Member

    Ah heck. Here's the whole script:

    global theList, ftpDirPath, pathname

    tell application "Tex-Edit Plus"
    if front window exists then
    if file of front window exists then
    copy (file of front window) to pathname
    copy pathname as string to pathname
    else
    my errorMessage("“" & (name of front window) & "” has not been saved yet.")
    end if
    else
    my errorMessage("There is no active document.")
    end if

    my TextToList(pathname as text, ":")
    if (get count of items of theList) = 4 then
    copy item 3 of theList to ftpDirPath
    else
    copy (item 3 of theList) & "/" & (item 4 of theList) to ftpDirPath
    end if

    tell application "Fetch 4.0.1"
    activate
    make new transfer window at front with properties {hostname:"someHost", userid:"someID", password:"*****", initial directory:ftpDirPath}

    put into transfer window "66.96.129.104" item pathname format Automatic without uniquename

    display dialog "Keep Fetch open?" buttons {"Yes", "No"} default button 2
    if the button returned of the result is "No" then
    quit Application "Fetch 4.0.1"
    end if

    end tell
    activate
    end tell

    on errorMessage(msg)
    display dialog msg buttons {"Cancel"} with icon note
    end errorMessage

    on TextToList(theText, theDelimiter)
    set saveDelim to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to {theDelimiter}
    set theList to every text item of theText
    on error errStr number errNum
    set AppleScript's text item delimiters to saveDelim
    error errStr number errNum
    end try
    set AppleScript's text item delimiters to saveDelim
    return (theList)
    end TextToList

    Posted 22 years ago #

  • DougAdams Member

    Ooops.

    The line:

    copy pathname as string to pathname

    Is part of troubleshoot, not part of script.

    Posted 22 years ago #

  • Jim Matthews Administrator

    Could you try this script:

    tell application "Fetch 4.0.1"
    set ftpDir to "example"
    make new transfer window at beginning with properties {hostname:"ftp.fetchsoftworks.com", userid:"", password:"", initial directory:ftpDir}
    end tell

    Does that work? Does it work if you replace the hostname, userid, password and directory with the ones you are trying to use?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • DougAdams Member

    Yes, the above code works. Assigning the variable like that works everytime.

    It's looking like this is <i>most probably not</i> a problem with Fetch, then, but perhaps with the coercing of the file variable.

    Thank you so much for your time and help with this!

    Posted 22 years ago #

  • DougAdams Member

    Well now I'm not so sure.

    I used choose file and eliminated the Tex-Edit routine and still got the mismatch:

    copy (choose file) to pathname

    set saveDelim to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to {":"}
    set theList to every text item of (pathname as text)
    on error errStr number errNum
    set AppleScript's text item delimiters to saveDelim
    error errStr number errNum
    end try
    set AppleScript's text item delimiters to saveDelim

    copy item 3 of theList to ftpDirPath

    tell application "Fetch 4.0.1"
    activate
    make new transfer window at front with properties {hostname:"somehost", userid:"someID", password:"somePW", initial directory:ftpDirPath}
    put into transfer window "somehost" item pathname format Automatic without uniquename
    end tell

    Could it be an AppleScript error??? I'm way stumped.

    Posted 22 years ago #

  • Jim Matthews Administrator

    That script works for me. What happens if you replace the tell application "Fetch 4.0.1" block with just:

    ftpDirPath

    and then see what shows up in the result window?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • DougAdams Member

    I get the correct string. Although the font it is "written" in in the result window is somewhat larger than a normal variable would be. I'm using the default AppleScript formatting; ftpDirPath's string is the same size as error text font from the Event window. Do you know what I mean? I hadn't noticed that before.

    Posted 22 years ago #

  • DougAdams Member

    Whoa.

    Just for the heck of it I ran the script from "Smile" and it worked perfectly. Actually, I ran it six different times and it ran perfectly each time.

    Thanks again for your time and gracious replies. I will root this out from another angle.

    Posted 22 years ago #

  • dgdavidson Member

    I'm getting the same problem but I'm using a different approach then this.

    I'm converting a script originally used with Anarchie.

    Here it is:

    -- path on the local drive to virtual website
    property FileRoot : "hd:Users:xx:website:"
    -- server domain name
    property HostName : "www.xxx.com"
    property ServerRoot : "//xxx/"
    property UserName : "yyy"
    property UserPassword : "zzz"

    on open DraggedFiles
    repeat with CurrentFile in DraggedFiles
    set CurrentFile to (CurrentFile as string)
    UploadFile(CurrentFile)
    end repeat
    end open

    on UploadFile(filepath)
    if filepath does not start with FileRoot then return

    set doc to (filepath as string)

    set filePathStart to (length of FileRoot)
    set filePathEnd to (the length of filepath)
    set FileSubPath to (text filePathStart thru filePathEnd of filepath)

    try
    set oldDelimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ":"
    set ServerSubPath to text items of FileSubPath
    set AppleScript's text item delimiters to "/"
    set ServerSubPath to (ServerSubPath as string)
    set AppleScript's text item delimiters to oldDelimiters
    on error
    set AppleScript's text item delimiters to oldDelimiters
    display dialog "There was an error!" with icon stop
    end try

    set serverPath to (ServerRoot & ServerSubPath as string)
    set preFix to "ftp://" & UserName & ":" & UserPassword & "@" & HostName
    set sendHere to (preFix & serverPath as string)

    if serverPath = "" then
    specify_destination()
    end if

    if serverPath != "" then

    with timeout of 60000 seconds
    tell application "Fetch 4.0.1"
    put into url sendHere item doc
    end tell
    end timeout
    end if
    end UploadFile

    on specify_destination()

    display dialog "Only works with dragged files. Edit destination with Script Editor."

    end specify_destination

    ------- any and all help greatly appreciated!!

    Posted 22 years ago #

  • Jim Matthews Administrator

    What error do you get? Could you post the contents of the Script Editor Event Log window?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • dgdavidson Member

    Originally posted by JimMatthews:

    What error do you get? Could you post the contents of the Script Editor Event Log window?

    Thanks,

    Jim Matthews
    Fetch Softworks

    When running this script I get:

    "A descriptor type mismatch has occured"

    and Script Editor highlights the following code:

    "put into url sendHere item doc"

    I've never completely understood the business with alias vs file vs item and so on. I suspect that somewhere something is a string and it shouldn't be but I have tried every combination I can think of with no help. I'm sure this is very simple to fix but I don't see it.

    Posted 22 years ago #

  • Jim Matthews Administrator

    The "item" parameter of the put into event should be an alias, so try changing it to this:

    put into url sendHere item alias doc

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • dgdavidson Member

    Originally posted by JimMatthews:

    The "item" parameter of the put into event should be an alias, so try changing it to this:

    put into url sendHere item alias doc

    Jim Matthews
    Fetch Softworks

    That didn't do it either, got the same error.

    :()

    Posted 22 years ago #

  • Jim Matthews Administrator

    What shows up in the Event Log window in Script Editor?

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • dgdavidson Member

    Originally posted by JimMatthews:

    What shows up in the Event Log window in Script Editor?

    Jim Matthews
    Fetch Softworks

    tell Application "Fetch 4.0.1"

    put into url "ftp://user :password@www.mydomain.com//user/xxx/yyy.txt" item alias "HD:Users:joe:website:xxx:yyy.txt"

    --> Fetch 4.0.1 got an error: A descriptor type mismatch occurred.

    [This message has been edited by dgdavidson (edited 11-07-2001).]

    [This message has been edited by dgdavidson (edited 11-07-2001).]

    Posted 22 years ago #

  • ActiveMac Member

    I am experiencing a problem which might be the same thing. I have narrowed it down to (unintentionally) sending Styled Text to Fetch.

    The following script should replicate the problem. Using a folder name from the Finder changes the text to styled text (at least that's how it looks in Script Debugger). I'm on OS X 10.1.2 with Fetch 4.0.1.

    set vHost to "ftp.yourserver.com"
    set vPass to "password"
    set vUser to "username"

    set vPath to "/dir"

    set vFolder to choose folder
    tell application "Finder"
    copy name of vFolder to vPathAdd
    copy vPath & "/" & vPathAdd to vPathStyled
    end tell

    tell application "Fetch 4.0.1"
    make new transfer window at beginning with properties {hostname:vHost, initial directory:"", userid:vUser, password:vPass}
    --path as text constant
    set current directory of transfer window vHost to "/dir"
    --path as non-styledtext variable
    set current directory of transfer window vHost to vPath
    --path as styled text variable
    set current directory of transfer window vHost to vPathStyled
    end tell

    Posted 22 years ago #

  • Jim Matthews Administrator

    Yes, Fetch 4.0.1 has trouble with styled text. It also has trouble with Unicode text, which AppleScript 1.7 (part of Mac OS 9.2.2) uses. These problems will be fixed in Fetch 4.0.2. In the meantime you can turn styled or Unicode text into a form that Fetch will understand by specifying it "as text". So instead of saying:

    alias "Macintosh HD:foo.gif"

    you'd say:

    alias (Macintosh HD:foo.gif" as text)

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

  • ActiveMac Member

    I tried changing

    copy name of vFolder to vPathAdd
    (to)
    copy (name of vFolder as text) to vPathAdd

    I still got styled text. I also tried changing

    set current directory of transfer window vHost to vPathStyled
    (to)
    set current directory of transfer window vHost to (vPathStyled as text)

    Still styled text, same error.

    Posted 22 years ago #

  • Jim Matthews Administrator

    A couple things to try:

    1) Leave out the "of transfer window vHost" part. If the transfer window is frontmost Fetch assumes that's the one you are talking about, and this might work around a bug in 4.0.1.

    2) Try "as string" instead of "as text".

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 22 years ago #

Topic closed

This topic has been closed.