Jump to content

LDAP Directory Search


Recommended Posts

I have my university/employer's LDAP directory set up in the Contacts app. Is there any way I can have Alfred search that directory other than a Custom Web Search? The custom web search works, but it'd be easier to have the results show up directly in Alfred and then be able to email them. I couldn't find any workflows matching this.

Link to comment

I have my university/employer's LDAP directory set up in the Contacts app. Is there any way I can have Alfred search that directory other than a Custom Web Search? The custom web search works, but it'd be easier to have the results show up directly in Alfred and then be able to email them. I couldn't find any workflows matching this.

 

Does Spotlight index these Contacts? I've never had LDAP configured on a Mac to know if Spotlight does or not

Link to comment
  • 2 weeks later...

Just following up on this thread, because this functionality would be AWESOME.  Is it doable?

 

I don't think it is if Spotlight doesn't index those contacts as well. Alfred searches using metadata created by Spotlight's metadata server so, if Spotlight can't find it, neither can Alfred. It may be possible with a workflow but I have no way of testing or trying this to find out.

Link to comment

I don't think it is if Spotlight doesn't index those contacts as well. Alfred searches using metadata created by Spotlight's metadata server so, if Spotlight can't find it, neither can Alfred. It may be possible with a workflow but I have no way of testing or trying this to find out.

 

I was under the impression that Alfred 2 switched from using Spotlight to using the contacts API for contacts access. I have no idea if that API provides LDAP/Exchange access though.

Link to comment
  • 3 months later...

Hello,

this would indeed be an awesome feature.

Let's assume we could find a way to query LDAP using a script (python for instance, may be bash), 1) is there a way to display a list of result based on keyword ? like when indexed files are being listed for instance ? We would then need to be able to 2) clic on a item out of the full list to call the script again (or an other) passing as query the person we would need the full detail from ?

 

I'm new to Alfred and I'm trying to play around, but I don't see so far how to achieve 1) and 2) ...

Is it possible to do this ? I would love to have a full integration of search results within Alfred nice designed lists.

 

O.

Link to comment

Hello,

this would indeed be an awesome feature.

Let's assume we could find a way to query LDAP using a script (python for instance, may be bash), 1) is there a way to display a list of result based on keyword ? like when indexed files are being listed for instance ? We would then need to be able to 2) clic on a item out of the full list to call the script again (or an other) passing as query the person we would need the full detail from ?

 

I'm new to Alfred and I'm trying to play around, but I don't see so far how to achieve 1) and 2) ...

Is it possible to do this ? I would love to have a full integration of search results within Alfred nice designed lists.

 

O.

 

Script filter workflows are definitely designed to do stuff like this. Script filters allow you to generate your own results for Alfred and have them shown in the main interface as a list of results (just like a file search would). Selecting one of the options could pass data associated with it to another script to do whatever you wanted. 

Link to comment

Ok, I found a way to query ldap and get some results formated to generate feedbacks.

But I'm trying to achieve this with Python and I'm currently stuck with what should be a basic!

I can't generate feedback using python. I saw some library out there that ease this phase, but I would like to have a full integrated script that does not need extra import or module install. So just trying basic XML generation from within workflow. But without success ...

 

Any idea why the following "Run Script" bloc (/usr/bin/python) does not work ?

print("<?xml version=\"1.0\"?>")
print("<items>")
print("<item uid=\"id1234\" arg=\"{query}\" valid=\"YES\"")
print("<title>Olivier HO-A-CHUCK</title>")
print("<subtitle>tel: +33 123456789 - email: its.me@gmail.com</subtitle>")
print("<icon type=\"fileicon\">/Applications/Contacts.app</icon>")
print("</item>")
print("</items>")

If I link to a notification bloc, the query is passed ok, but I can't get feedback generated from it while using python.

 

I might not doing it right in term of how workflow does work ?

 

Any help would be appreciated.

Here is a sample Workflow I was expecting to work, but does not ...

 

Olivier.

Link to comment

Ok, I found a way to query ldap and get some results formated to generate feedbacks.

But I'm trying to achieve this with Python and I'm currently stuck with what should be a basic!

I can't generate feedback using python. I saw some library out there that ease this phase, but I would like to have a full integrated script that does not need extra import or module install. So just trying basic XML generation from within workflow. But without success ...

 

Any idea why the following "Run Script" bloc (/usr/bin/python) does not work ?

print("<?xml version=\"1.0\"?>")
print("<items>")
print("<item uid=\"id1234\" arg=\"{query}\" valid=\"YES\"")
print("<title>Olivier HO-A-CHUCK</title>")
print("<subtitle>tel: +33 123456789 - email: its.me@gmail.com</subtitle>")
print("<icon type=\"fileicon\">/Applications/Contacts.app</icon>")
print("</item>")
print("</items>")

If I link to a notification bloc, the query is passed ok, but I can't get feedback generated from it while using python.

 

I might not doing it right in term of how workflow does work ?

 

Any help would be appreciated.

Here is a sample Workflow I was expecting to work, but does not ...

 

Olivier.

 

Run Script items are the correct item to be generating feedback with. Trying using a Input->Script Filter item. Let m know if that solves your issue

Link to comment

Unfortunately, it does not help at all ...

I had tried this already (but just double checked and did again - cf. new sample workflow).

 

:(

 

Actually, I don't know if it's a good news or not (might be good), but I can't even generate feedback using perl as well (see bellow):

print "<?xml version=\"1.0\"?>\n";
print "<items>\n";
print "<item uid=\"id1234\" arg=\"{query}\" valid=\"YES\"\n";
print "<title>Olivier HO-A-CHUCK</title>\n";
print "<subtitle>tel: +33 123456789 - email: its.me@gmail.com</subtitle>\n";
print "<icon type=\"fileicon\">/Applications/Contacts.app</icon>\n";
print "</item>\n";
print "</items>\n";

I should do something wrong !!! but what can this be ...  :rolleyes:

 

Edit:

It's look like, I'm getting closer but not there yet fixed ...

Consol say it's an NSXMLParserErrorDomain error 68. This might be an encoding issue.

21/11/13 15:57:17,756 Alfred 2[1754]: [ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=68 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 68.)" UserInfo=0x600000472580 {NSXMLParserErrorColumn=1, NSXMLParserErrorLineNumber=4, NSXMLParserErrorMessage=error parsing attribute name
}

I'm french and my mac is in French ... I don't know is there is a link (or if this could even be linked to the issue ...). 

I'm still open to any ideas ...
 
O.
Edited by _oho
Link to comment

 

Unfortunately, it does not help at all ...

I had tried this already (but just double checked and did again - cf. new sample workflow).

 

:(

 

Actually, I don't know if it's a good news or not (might be good), but I can't even generate feedback using perl as well (see bellow):

print "<?xml version=\"1.0\"?>\n";
print "<items>\n";
print "<item uid=\"id1234\" arg=\"{query}\" valid=\"YES\"\n";
print "<title>Olivier HO-A-CHUCK</title>\n";
print "<subtitle>tel: +33 123456789 - email: its.me@gmail.com</subtitle>\n";
print "<icon type=\"fileicon\">/Applications/Contacts.app</icon>\n";
print "</item>\n";
print "</items>\n";

I should do something wrong !!! but what can this be ...  :rolleyes:

 

Edit:

It's look like, I'm getting closer but not there yet fixed ...

Consol say it's an NSXMLParserErrorDomain error 68. This might be an encoding issue.

21/11/13 15:57:17,756 Alfred 2[1754]: [ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=68 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 68.)" UserInfo=0x600000472580 {NSXMLParserErrorColumn=1, NSXMLParserErrorLineNumber=4, NSXMLParserErrorMessage=error parsing attribute name
}

I'm french and my mac is in French ... I don't know is there is a link (or if this could even be linked to the issue ...). 

I'm still open to any ideas ...
 
O.

 

 

If you are entering foreign/accented characters then yes this would probably cause an issue. We've seen issues with this before. Andrew tried multiple ways of encoding and normalizing user input but we weren't able to nail down an exact fix for this. Otherwise, the XML you have appears to be correct. Have you taken a look at the example workflows included with Alfred? In the Workflows area, click the + in the bottom left as if you were going to create a new workflow and select the Script Filter XML Format example and take a look through it.

Link to comment
I have tried this already. And the sample (with bash) work well (no error in console either).

I have actually started by playing around from this sample. But I did not succeed in achieving requesting ldap and parsing the result with bash so I changed to python. And this is were I start having problems ...

Did you ever succeed in providing feedback (even simple) using python script (or perl) ? 

Could you try my provided with first python sample workflow (see if it works in your mac environment) ?
Link to comment

 

I have tried this already. And the sample (with bash) work well (no error in console either).
I have actually started by playing around from this sample. But I did not succeed in achieving requesting ldap and parsing the result with bash so I changed to python. And this is were I start having problems ...
Did you ever succeed in providing feedback (even simple) using python script (or perl) ? 
Could you try my provided with first python sample workflow (see if it works in your mac environment) ?

 

 

Found it 

 

The opening item tag isn't terminated at the end of the line, add the necessary > at the end to fix it   :)

Link to comment

Hello David,

 

Thank you for your finding!

It's a shame for me that you had to spend time on such kind of easy/stupid issue.  :wacko:

 

Unfortunately it's the week-end and I can't really test much on integration with ldap request. I'll have to wait for monday to play around (space with name, deal with special char, etc.). But before leaving the office yesterday, I could quickly check that I can indeed get ldap result from Alfred and display them as a list with contact icon. 

For some reason I couldn't get it right from Script Filter and I had to dome something as you propose in your sample with:

1) "Script Filter" (get the keyword) + 2) "Action" -> "Run Script" (process {query} with Python and write an xml formatted result to a file + 3) call via "Output -> Run Script" oascript a new "Alfred 2" search + 4) "input"  -> "Script Filter" that display xml file content (list of result).  I'll check this week-end if I can do something less "complicated".

 

I still have now to figure out how to display a full page when I click on a name from the list (like contact detail page does). I hope this is possible ? It would be great to create a new email if clicked on email detail, launch SIP call if it's a fix line, call iMessage if it's a mobile number, etc. Also, It might even be possible to display person picture as I believe I can get this info from ldap ... 

 

Once I'll have the all workflow working I'll post it there for those that have ldap directory at the office.

 

Thank you again David for your support.

 

O.

Edited by _oho
Link to comment

Hello David,

 

Thank you for your finding!

It's a shame for me that you had to spend time on such kind of easy/stupid issue.  :wacko:

 

Unfortunately it's the week-end and I can't really test much on integration with ldap request. I'll have to wait for monday to play around (space with name, deal with special char, etc.). But before leaving the office yesterday, I could quickly check that I can indeed get ldap result from Alfred and display them as a list with contact icon. 

For some reason I couldn't get it right from Script Filter and I had to dome something as you propose in your sample with:

1) "Script Filter" (get the keyword) + 2) "Action" -> "Run Script" (process {query} with Python and write an xml formatted result to a file + 3) call via "Output -> Run Script" oascript a new "Alfred 2" search + 4) "input"  -> "Script Filter" that display xml file content (list of result).  I'll check this week-end if I can do something less "complicated".

 

I still have now to figure out how to display a full page when I click on a name from the list (like contact detail page does). I hope this is possible ? It would be great to create a new email if clicked on email detail, launch SIP call if it's a fix line, call iMessage if it's a mobile number, etc. Also, It might even be possible to display person picture as I believe I can get this info from ldap ... 

 

Once I'll have the all workflow working I'll post it there for those that have ldap directory at the office.

 

Thank you again David for your support.

 

O.

 

Well, displaying an info page wouldn't be too complicated I don't think. If you could set the url to the contact's info as the argument to that result, you could press Shift or Cmd+Y to quick look that result and see the info page there. For the images, that's a little more trouble right now. Alfred 2 currently doesn't have the ability to use urls to display icons for results so, to get this to work you would have to download each icon, save it to a file and then reference that file as the icon. It's not complicated but will definitely affect performance when searching.

Link to comment

You could always cache the icons in a data directory to make it go faster. You'd run into lag the first time the icon would appear in Alfred, but subsequent use would make it much faster. So, in the script, you'd just do a check to see if the icon exists in the data directory; if it does, then you use that; if it doesn't, then the script will download it and then reference it. You might need to setup some sort of indexing file, say an xml file that maps the identifier to the correct icon file, but that depends on the origins of the file names; if the file names are unique from the source and easily identifiable, then you shouldn't need to do that.

Link to comment

Hello David and Shawn,

thank you for your suggestions.

 

I think I understand that for displaying result, I should generate for each contact a local html page so that I can popup (Shift or Cmd+Y) a preview url to show contact details. Correct ?

I had initialy a secret expectation to be able to trick Alfred system and use contact detail display page (where you can select each element like, phone, email, etc.), see the person picture exactly like contact detail page show it, etc. I understand that this is not achievable as Alfred2 contact detail page is really a build-in non customer available type of page display. Right ? Is there any trick I could use (except may be creating/adding on the fly a real contact when selecting a result)?

 

Concerning contact icons/images, so far, I can't get them from ldap (I need to do authenticated request that I don't know yet how to do - I'm reverse engineering company IS there) so I'll postpone some thinking on caching and performance management until then (thank for your reco Shawn).

 

The good news:

I could test/fix this morning (Paris time) a workflow which is now fully working:

1) get search key from 'ldap' keyword

2) display result as list of names (with phone number and email as subtitle)

3) click on name does initiate a call through DeskConnect (I saw this week-end post on the app applescript integration - I was already using this app and didn't used this feature before => awesome)

 

The good part:

the workflow is more than 10 times faster than other internal company solutions (query from contact app, or web intranet/interface).

 

I have committed the workflow to github as I don't know how to attach a file here (do I need to be more senior in the forum to be able to share attachments ?).

Here is LDAP.alfredworkflow for download from github.

 

If someone want to use this workflow, some settings need to be customised (like ldap server url, domain, etc. - see python script for more details).

Also, launching DeskConnect could be replaced by SIP call or email sending for instance.

 

Quick other question: is there a way I could suggest a key option for choosing action from names list like "DeskConnect call" or "send email" ?

 

O.

Link to comment

I think I understand that for displaying result, I should generate for each contact a local html page so that I can popup (Shift or Cmd+Y) a preview url to show contact details. Correct ? [...] Right ? Is there any trick I could use (except may be creating/adding on the fly a real contact when selecting a result)?

 

Quick other question: is there a way I could suggest a key option for choosing action from names list like "DeskConnect call" or "send email" ?

 

I've had a lot of fun trying to come up with navigable interfaces for Workflows, but I also find that they are, often, overkill and require you to take your hands off the keyboard, which helps defeat one of the main benefits of Alfred, so I'd recommend staying away from any pop-up if possible (if you do need to do this, however, generate the html, store it like I described with the icons, and create an automator application that simply uses the display webpage in a pop-up action: don't specify the options, but, instead, send the url as an argument through a bash script using "open <application-name> --args <url--file://full-system-path-to-cached-file>" You can specify the dimensions of the popup window within the automator application. After that, put in a quick "sleep" to wait for the application to open (like 100ms) and then use applescript to "active" it. You might have to activate it twice in order to get the focus on it correctly. Then, set the tab ordering on the html so that people can just tab through the links. Look into application uri's to make sure that you open the link in the right application -- for instance, try open dict://test in a terminal.).

 

So, if you do want to stay away from an interface, what you can do is use a method called "drill down menus." David wrote a sample workflow that shows how to use them, but I can't find it that quickly. But, you can look at this thread for a better idea.

 

Basically, what you would do would just have the initial search be for the user. After that, you'd select the user and then, after selection, each bit of "feedback" in the script would give the options of "Email" "Call" etc... Then you'd easily be able to just press Cmd+5 or something to select email.

 

For the hotkeys and arguments, I think that you're looking at passing arguments via the hotkeys... maybe? Look for Tyler Eich's "Colors" workflow to see how that can be done. There are a bunch that use them as well, but I can't remember them off the top of my head.

Link to comment

Oh, and remember that hotkeys are stripped when a user imports the workflow, so you won't be able to set them for the user, although you can set the modifiers.

 

Also, there are a lot of libraries out there that can help you with LDAP authentication. Here's a stackoverflow thread that references a python library. There's probably a library for just about every language out there. I know that LDAP support is bundled into the php-cli for Mavericks. If you're using a previous version, double check because they upgraded php from 5.3 to 5.4 between Mountain Lion and Mavericks. Just open a terminal and type 'php -i' and you'll get a long list about how php is configured. For Mavericks, the relevant part shows

ldap

LDAP Support => enabled
RCS Version => $Id$
Total Links => 0/unlimited
API Version => 3001
Vendor Name => OpenLDAP
Vendor Version => 20428
SASL Support => Enabled
Link to comment

Wouao!! This is a lot of information.

Thank you very much Shawn!

 

I'll have a look a those as soon as possible.

Since my post I have added a quick extra Apple script (not yet committed) that add the contact to local contact app (only when selected for dialling over DeskConnect). So that it will be part of local result when searching for this contact the next time.

Next step will be to work with authentication for getting more ldap info (in particular person picture).

 

I love Alfred !

 

O.

Link to comment

Just a quick note:

 

If you share the workflow with the included applescript, make sure that you let everyone know that it adds contacts locally when selecting that option. I'm a fan of full disclosure when it comes to modifying any information on someone's system that isn't obvious (i.e. "This workflow interacts with Omnifocus" doesn't need a disclaimer that it manipulates OmniFocus' database). Adding a contact locally can be great, but people should know that their address books will start to get a few more entries.

 

Glad you're loving it. It really does make our computer lives nicer and faster.

Link to comment

You are right.

Just before reading at your post, I was even asking myself if this should not be something separate like either call from ldap, either add to address book.

It's always goo to keep things as simple and basic as possible.

But if I keep it mixed up, I will make it very clear (100% agreed with you).

In a mean time, I told too fast that it was done, as if the principle of adding a contact was tested and validated with the Applescript, I still have to add some more processing to get all the fields passed into the query and spread again in all different address book fields after. :)

I'll do that once, I'll have all the magic fields missing (image, mobile number, address, department, SIP address, etc.).

 

O.

Link to comment
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...