hi
I have been successfully using the below code that StefanK wrote a while back in an application that I built with no issues, recently though it has failed to load the popup menu with the items ending in “CSOPQ” & “SOPQ”, throwing an error in the log as per below, I really have no idea where to start or how to fix this issue, would any one have any ideas as to why it is failing?, or solutions to help fix.
Error:
2012-12-03 09:09:48.733 test find issue[30503:707] *** -[test_find_issueAppDelegate queryDidFinish:]: unrecognized function stringByDeletingPathExtension. (error -10000)
script test_find_issueAppDelegate
property parent : class "NSObject"
property aPopupMenu : missing value
property NSPredicate : class "NSPredicate"
property NSMetadataQuery : class "NSMetadataQuery"
property NSNotificationCenter : class "NSNotificationCenter"
property query : NULL -- variable for the NSMetadataQuery instance
on CanStockOpaques_(sender)
makeMenu_("CSOPQ", -1)
end StockOpaques_
--
on StockOpaques_(sender)
makeMenu_("SOPQ", -1)
end StockOpaques_
--------------------------
--
--------------------------
on makeMenu_(searchString)
NSNotificationCenter's defaultCenter's addObserver_selector_name_object_(me, "queryDidFinish:", "NSMetadataQueryDidFinishGatheringNotification", missing value)
set pathExtension to "ps"
set searchPath to "/Volumes/RIP FILES/"
set searchKey to quote & "*-" & searchString & "*." & pathExtension & quote
--set searchKey to quote & "*" & searchString & "*." & pathExtension & quote
set predicate to NSPredicate's predicateWithFormat_("kMDItemFSName like[c] " & searchKey)
set query to NSMetadataQuery's alloc()'s init()
query's setSearchScopes_({searchPath})
query's setPredicate_(predicate)
query's startQuery()
end makeMenu_
on queryDidFinish_(theNote)
query's stopQuery()
aPopupMenu's removeAllItems()
set foundItems to theNote's |object|()'s results()
set sorter to current application's NSSortDescriptor's sortDescriptorWithKey_ascending_("kMDItemFSName",1)
set foundItems to foundItems's sortedArrayUsingDescriptors_({sorter})
repeat with anItem in foundItems
aPopupMenu's addItemWithTitle_(anItem's valueForAttribute_("kMDItemFSName")'s stringByDeletingPathExtension())
aPopupMenu's lastItem()'s setRepresentedObject_(anItem's valueForAttribute_("kMDItemPath"))
end
NSNotificationCenter's defaultCenter's removeObserver_(me)
end queryDidFinish_
--------------------------
--
--------------------------
end script
stringByDeletingPathExtension is an NSString’s instance method, thus requiring the object to be an NSString to work. valueForAttribute: returns an id object. perhaps if you created an NSString object first? Things might have changed there too in 10.7. haven’t tried it, just saw this being a potential lead to the problem.
Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)
Try rewriting that section as separate steps and log the results:
set theName to anItem's valueForAttribute_("kMDItemFSName")
log "Name: " & theName as text
set theTitle to theName's stringByDeletingPathExtension()
log "Title: " & theTitle as text
aPopupMenu's addItemWithTitle_(theTitle)
I am pretty sure that you’re trying to use an instance method on an object that does not have this method. Try creating an NSString object with the value you get from the valueForAttribute: method.
which probably means that either the file does not exist or that there is no such information (kMDItemFSName). Using spotlight is sometimes a bit shaky. maybe rebuild the index could help?
tried logging foundItems & theName, what was returned was this
2012-12-03 13:52:48.273 test find issue[31548:707] *** -[test_find_issueAppDelegate queryDidFinish:]: Can’t make «class ocid» id «data kptr00000000A059E80004000000» into type Unicode text. (error -1700)
I re-indexed spotlight, twice, just to see if it improved the problem, it did but it’s pretty flaky, if I click on the button
on CanStockOpaques_(sender)
the result will display in the popup, I then go and select another button click on that, it’s item shows in the popup, I go back to my first button, click, nothing shows in the popup, very flaky indeed, so it appears that the code is working, intermittently though.
The files are definitely there, all 150 or so of them.
I don’t no how to implement “nsstring’s stringWithString class method” so couldn’t try this idea.
I did how ever go back and re,re, re-index the drive, updated to 10.7.5, ran disk warrior & tech tool pro
the problem has stopped for the “CSOPQ” & “SOPQ” but now wont acknowledge files ending in “CPNSOPQ”
so i’m guessing iv’e got a real flaky spotlight issue.