I am trying to resolve an issue with looking up records with file, where the filename has a forward slash ‘/‘ in the name.
If I just lookup records with file “File/Name”, it won’t return any results even if the actual file is there right in fron of me.
If I inspect the properties of the record of that file, it will show that internally the name of the file is “File-Name”. That’s fine with me; if your internal filing uses POSIX then forward slashes are not your thing, and I can work around that. However, lookup records with file “File-Name” also returns nothing.
I read in another post that DNtp’s lookup with file is rather broken in v3. Is there a way around this?
(The obvious answer is: don’t use files with forward slashes in the name - but that is not an option at the moment)
(The obvious answer is: don’t use files with forward slashes in the name - but that is not an option at the moment)
Why?
Is there a mandated naming convention you must adhere to corporately?
I read in another post that DNtp’s lookup with file is rather broken in v3.
I’m not sure where you read that but it’s certainly untrue. DEVONthink 3’s search is far superior to previous versions of DEVONthink and improving all the time.
Non-alphanumeric characters are 99% not indexed. However, I’m having no issue finding such a file…
I am capturing (“scraping”) articles from a website using Safari. I have to do this via Safari because DNtp’s authentication does not work there. Using AppleScript, I load the individual articles from their link into a Safari window, then copy the source from that window into an html record in a DNtp database. These articles have inline attachments (.doc, .xls, .ppt, etc), with a filename and link. Again, using AppleScript, I tell Safari to open that link, which downloads the file to the Downloads folder. I then rename the file using the name that I have and import it into the DNtp database where the articles are. Then I rewire the links in the article inside the DNtp database to point the attachment links to the actual attachment inside the DNtp database.
The rewiring of the link happens in AppleScript. Since the script can find the name of the attachment in the source text, all it needs is to find the attachment in the database with that name and change the link to an internal DNtp link (saving the original link text as a comment in the link in the source file, so I can always get that back).
This works for almost all files – except for those that have a ‘/’ in the name. Eg. assuming there are two files named: file-name.doc and file/name.doc, then:
lookup records with file “file-name.doc” returns the result for file file-name.doc
lookup records with file “file/name.doc” returns… nothing. Empty record.
The properties for the file “file/name.doc” in DNtp shows the internal name being “file-name.doc”, but it cannot be found with that name either (only if the original name had been “file-name.doc”).
I should add that if, by means of AppleScript, you try to rename a file in the Finder to a name with a colon “:”, the Finder automatically transposes the colon for a forward slash “/”.
The disk I’m working on is APFS and as far as the MacOS Finder is concerned, the directory separators are still “:” - you can’t give a file a name with a colon “:” but you can give a file a name with a forward slash “/”… just like you can on Windows where the files are coming from.
However, as you say, in POSIX this is reversed: you can give files a name containing a “:” but not a “/”.
Now, here’s the weirdness:
If, in MacOS, you give a file a name containing a ‘/’ all applications using the standard file interface see this as a ‘/’ but those insisting on POSIX see a “:”. So, as far as DNtp is concerned, considering internally it uses POSIX references, any forward slashes ‘/’ in the filename are translated into “:”. If using ‘lookup record with file’ in AppleScript, then you don’t lookup record with file “file/name.txt” – even if the name representation in the database still contains a ‘/’ – but with file “file:name.txt”.
What makes this confusing is that when you ask for properties of the record in AppleScript, the filename will be described as “file-name.txt” – with a hyphen, not a slash or a colon.
What makes this extra confusing is that in the Search Box in DNtp you would still refer to “file/name.txt” as Bluefrog describes - not “file:name.txt” or “file-name.txt”.
tell application id "DNtp"
try
set theName to "Datei mit / im Namen.txt"
set theSearchName to theName
if theName contains "/" then
set theSearchName to my replace_String(theName, "/", ":")
end if
set theResults to lookup records with file theSearchName
if theResults = {} then
set theSearchName to my replace_String(theName, "/", "-")
end if
set theResults to lookup records with file theSearchName
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
on replace_String(theText, oldString, newString)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replace_String
The name (the one shown in DEVONthink’s interface) is indexed & searchable but not the filename. Now do you want to actually lookup the filename or the name?
Thanks for this. This is roughly what I did.
If theFileName is the original name of the file (with or without a forward slash), then:
set text item delimiters to "/"
set thefileName to text items of theFileName
set text item delimiters to ":"
set theFileName to theFileName as string
tell app id "DNtp"
set myRecords to lookup records with file theFileName in database "Articles"
….
end tell
I’m trying to lookup the filename - not the name of the file in the name field of the file record.
Basically, I was trying to resolve the following, where the selection is a file that was imported into the database “Articles”:
tell application id "DNtp"
set myRecord to (item 1 of (get the selection))
set theFileName to filename of myRecord
set myRecords to lookup records with file theFileName in database "Articles"
end tell
If the original name of the file contains no forward slashes, the lookup returns a list with the record of that file.
If the original name of the file DID contain forward slashes, the lookup returns an empty list. So: I just retrieved the filename from that record but when I look it up it’s not there any more.