Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indirectobject parameter to AppleScript action handlers #366

Merged

Conversation

ddlsmurf
Copy link
Contributor

@ddlsmurf ddlsmurf commented Jun 9, 2011

In scripts in ~/Library/Application Support/Quicksilver/Actions/, it is now possible to accept an indirect object, example:

using terms from application "Quicksilver"
  on process text dObject with iObject
    activate
    display dialog "Direct is '" & dObject & "' indirect is '" & iObject & "'" buttons {"OK"} default button 1
  end process text
  on get argument count
    return 2
  end get argument count
end using terms from

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 9, 2011

I wish I knew enough about the interaction with AppleScript to be more helpful, but using your example as an action, I’m getting this in the console:

6/9/11 3:10:03 PM   Quicksilver[57723]  argument count for [Action]:/Users/rob/Library/Application Support/Quicksilver/Actions/Show Objects.scpt is 2
6/9/11 3:10:03 PM   Quicksilver[57723]  Perform AppleScript Action Error: "NSAppleScriptErrorRange" = NSRange: {0, 0};
  "NSAppleScriptErrorNumber" = -1701;
  "NSAppleScriptErrorMessage" = "The iObject parameter is missing for \U00abevent DAEDopnt\U00bb.";
  "NSAppleScriptErrorBriefMessage" = "The iObject parameter is missing for \U00abevent DAEDopnt\U00bb.";

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Jun 9, 2011

Can you check that:

  • you are recompiling the core support plugin ? (by default it's only done so in the distribution target)
  • there are no other Quicksilver.app or Core Support.qsplugin lingering on the FS
    And everytime you change something like that, you need to recompile the script so that it uses the new suite terms (this requires really editing and saving the script apparently) =(

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 9, 2011

you are recompiling the core support plugin ?

I almost always clean all targets and build the “Quicksilver Distribution” target.

there are no other Quicksilver.app or Core Support.qsplugin lingering on the FS

I’ll bet this is it. I was building with the Debug configuration, which left my copy in /Applications intact. This is most likely what Script Editor was looking at for terms. I’ll give it another try.

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 9, 2011

OK, it seems to work as advertised without affecting existing behavior. I’ll keep it active for a while to make sure I don’t run into any problems.

@pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Jun 12, 2011

I'll have a play today.

@pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Jun 12, 2011

I know @philostein has expressed his wishes for this behaviour. He might be helpful in testing this.

If you (philostein) don't want to have to get all fancy with git, here's a link to a QS version compiled with these changes.
https://github.com/downloads/pjrobertson/Quicksilver/Quicksilver.app.zip

For what it's worth, I've done some limited testing and it seems fine. Hopefully Phil will have plenty more ideas and tests :)

@philostein
Copy link
Contributor

@philostein philostein commented Jun 12, 2011

Thanks a bunch, I'll try it out.

This is great!

Searching in pane 3 returns any Object. If the Object is a file/folder, would it be possible for iObject to be a path string or preferably a file Object? So the Desktop folder in pane 3 would return:
/Users/phil/Desktop/
or preferably:
alias "320 of 500:Users:phil:Desktop"
It would then be possible to make custom Actions that are a lot more versatile.

I like the way pressing enter with an empty pane 3 returns a system beep error. Also pressing '.' in pane 3 allows a text Object to be typed.
Dismissing/activating the interface straight after putting an object in pane 3 causes QS to lose the script as a valid Action for pane 2. Judging by the subsequent Actions, I think QS starts treating the text Object as a file Object. Pressing '.' in pane 1 then tab, or changing the Action in pane 2 then dismissing/activating the interface reactivates it as a text Object.

I was able to create a Curent Selection>[AppleScript Action]>[Type to search] Trigger, no problem.

Cheers.

@pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Jun 12, 2011

I thought you'd have some ideas :)

Dismissing/activating the interface straight after putting an object in
pane 3 causes QS to lose the script as a valid Action for pane 2. Judging by
the subsequent Actions, I think QS starts treating the text Object as a file
Object.

This is a known problem, unrelated to this pull. The same thing happens if
you go 'Typed Text' ⇥ 'Find With...' wait a while then close and reopen the
window. QS assumes the item in the 1st pane has the type of the item that
was last in the 3rd pane (a web search URL in this case)
I think we have an issue on it, but not sure

On 12 June 2011 13:35, philostein <
reply@reply.github.com>wrote:

Thanks a bunch, I'll try it out.

This is great!

Searching in pane 3 returns any Object. If the Object is a file/folder,
would it be possible for iObject to be a path string or preferably a file
Object? So the Desktop folder in pane 3 would return:
/Users/phil/Desktop/
or preferably:
alias "320 of 500:Users:phil:Desktop"
It would then be possible to make custom Actions that are a lot more
versatile.

I like the way pressing enter with an empty pane 3 returns a system beep
error. Also pressing '.' in pane 3 allows a text Object to be typed.
Dismissing/activating the interface straight after putting an object in
pane 3 causes QS to lose the script as a valid Action for pane 2. Judging by
the subsequent Actions, I think QS starts treating the text Object as a file
Object. Pressing '.' in pane 1 then tab, or changing the Action in pane 2
then dismissing/activating the interface reactivates it as a text Object.

I was able to create a Curent Selection>[AppleScript Action]>[Type to
search] Trigger, no problem.

Cheers.

Reply to this email directly or view it on GitHub:
#366 (comment)

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 13, 2011

Maybe instead of a simple argument count, AppleScripts should be able to return two arrays: a list of types for the direct object and a list of types for the indirect object? Or perhaps if a user’s needs are that complex, we should say “Here’s a quarter, kid. Go and get yourself a real action.” (meaning Objective-C). :)

@philostein
Copy link
Contributor

@philostein philostein commented Jun 13, 2011

Remember 'Act without doing'? I want to 'Act without learning Objective-C'. :)

Is it feasible (and not too much effort) to return a file alias/path for the indirect object?
The direct object should always be text, as the 'process text' handler will only respond to that.

Perhaps QS could also only return files/folders when searching in pane 3, which would be similar to the way the 'Copy To…' Action returns only folders. This is not a deal breaker, as the script could just handle the error if it gets another object type.

@pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Jun 13, 2011

I don't know anything about AS dictionaries, but an alternative to Skurfer's method could be to add a new

path applescript action so you could do something like this:

using terms from application "Quicksilver"
  on process text dObject with iObject
    activate
    display dialog "Direct is '" & dObject & "' and the indirect object '" & iObject & "is a file with a path '" & iObject's path & "'" buttons {"OK"} default button 1
  end process text
  on get argument count
    return 2
  end get argument count
end using terms from

I use (current date)'s date string in an AS so I know it may be possible.
We could then allow file types in the 1st pane of Quicksilver as well.

I think improving support for AS is important; we'll never be able to know everything that users will want to do, and having a solid AppleScript implementation will make lives much easier for users who do want different actions

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 14, 2011

Remember 'Act without doing'? I want to 'Act without learning Objective-C'. :)

I’m just thinking if you want something, a lot of other people probably want it too so maybe it should be part of a plug-in. AppleScript is always Plan B. (And I felt that way looong before I learned anything about implementing Plan A.) :)

The direct object should always be text, as the 'process text' handler will only respond to that.

If the script is in the first pane, yes. But remember that only happens for scripts that are added to the catalog, not scripts in the Actions folder (which is what this change is about). I know you’ve added ~/Library/Application Support/Quicksilver/Actions to the catalog, but that’s not a default setup. Since these scripts are actions, they could potentially apply to anything.

@philostein
Copy link
Contributor

@philostein philostein commented Jun 14, 2011

@skurfer I see what you mean, and ideally proper plugins won't be written in AppleScript.

But… because of Quicksilver's plugin architecture, almost everything is possible. Yourself and other devs are never going to get around to writing plugins for all the apps that people would like to use through QS.

An example is Sparrow app. It has an AppleScript Dictionary that allows the sending of emails with attachments. An AppleScript that took an indirect file object in pane 3 could allow the user to write an email body and attach a file without leaving Quicksilver. I have a Script ready to go, it just needs an iObject file path to replace the hard-coded one. I say that's pretty useful in lieu of a dedicated plugin.

A file iObject would allow a lot more useful stopgap Actions for various plugin-less apps (dictionaries permitting).

The direct object should always be text, as the 'process text' handler will only respond to that.

If the script is in the first pane, yes. But remember that only happens for scripts that are added to the catalog, not scripts >in the Actions folder (which is what this change is about). I know you’ve added ~/Library/Application >Support/Quicksilver/Actions to the catalog, but that’s not a default setup. Since these scripts are actions, they could >potentially apply to anything.

Sorry, I meant the 'on process text' handler within the script. That can only receive text, so dObject has to be text, whether the script is in pane 1 and causing the 'Process Text…' Action, or in Pane 2 as a consequence of being in QS's Actions folder. Any object apart from text in pane 1 will stop the script appearing in pane 2. Unless I'm missing something.

If you're saying there's an 'on open file' handler that can take a file object and an indirect object of text or whatever, then that'd be cool. ;)

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 14, 2011

If you're saying there's an 'on open file' handler that can take a file object and an indirect object of text or whatever, then that'd be cool.

I don’t know. The Quick Look scripts uses on open of theFile. Have you tried using that in a script that returns an argument count of 2?

@philostein
Copy link
Contributor

@philostein philostein commented Jun 14, 2011

I don’t know. The Quick Look scripts uses on open of theFile. Have you tried using that in a script that returns an argument >count of 2?

It provides a pane 3, but the script refuses to go past on open _files with iObject
I'll play around with it some more.

@ddlsmurf any more info on this? Thanks!

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Jun 16, 2011

I am sorry, I cannot get any mac dev work done at the moment so I can't test any of that. On the other hand I'm having a hard time parsing what you want and how it relates to this pull request ?
The reason the objects get changed to text is because reconstructing AE equivalents is a big pain. If there is any support for it in QS, the original_dev of the process text handler thingie chose not to use it, and without further information nor will to debug, I think it's safest to go with just strings.

@philostein
Copy link
Contributor

@philostein philostein commented Jun 17, 2011

Thanks @ddlsmurf, I was asking if the iObject could convert a file Object into a text string of its file path.

If that's not possible, then no worries.

I guess it doesn't really relate to the pull request, Patrick asked me for some ideas. ;)

Cheers.

@skurfer
Copy link
Member

@skurfer skurfer commented Jun 30, 2011

So it sounds like nothing further is going to happen with this for now. Merge?

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Jun 30, 2011

(I am meaning to try and find out about the file path thing, just haven't gotten round to it yet sorry, I'd ask for some more time so we keep it under the same branch. It is possible to use a different string for the iObject, I just have to look into how to get the path - using stringValue seems insufficient)

@pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Jun 30, 2011

I just have to look into how to get the path - using stringValue seems
insufficient)

Try using validPaths: as defined in QSObject_FileHandling.h assuming you
want the path from a QSObject.
Not sure what you mean about 'a different string from the iObject'

I have no problems with this staying open until whichever of these two
happens first:

  • This iObject feature is implemented/sorted
  • We release a new QS version. In this case, it's probably best to merge
    what we've got then just extend it in a later release.

On 30 June 2011 19:33, ddlsmurf <
reply@reply.github.com>wrote:

(I am meaning to try and find out about the file path thing, just haven't
gotten round to it yet sorry, I'd ask for some more time so we keep it under
the same branch. It is possible to use a different string for the iObject, I
just have to look into how to get the path - using stringValue seems
insufficient)

Reply to this email directly or view it on GitHub:
#366 (comment)

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Jun 30, 2011

Ok I'll try validPaths, thanks! I assume by the name that it handles the comma trick, in which case how would you like your paths formatted ? (I really would prefer not creating an AE list)

@pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Jun 30, 2011

validPaths calls arrayForType:QSFilePathType which returns an array of
strings with the paths.
It also deals with the case when there's only 1 file (lines 652 of
QSObject_FileHandling.m onwards)

I don't quite understand what you mean by 'how would you like your paths
formatted?', sorry :(

On 30 June 2011 20:35, ddlsmurf <
reply@reply.github.com>wrote:

Ok I'll try validPaths, thanks! I assume by the name that it handles the
comma trick, in which case how would you like your paths formatted ? (I
really would prefer not creating an AE list)

Reply to this email directly or view it on GitHub:
#366 (comment)

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Jun 30, 2011

If you select multiple files in the indirect object, what should the applescript string look like ? Comma separated ? Perhaps some escaping ?

@philostein
Copy link
Contributor

@philostein philostein commented Jun 30, 2011

How about '/Users/phil/Test folders/Test folder 1/File test 1.rtf:/Users/phil/Test folders/Test folder 1/File test 2.rtf' (no quotes)? The iObjects are separated by a colon, which is an illegal character for filenames.

It'd probably be best to use POSIX paths as file locations are separated by colons and would be harder to delimit, and POSIX paths can be piped into a 'do shell script' command or changed to neutral file location strings:

set _pathsString to "/Users/phil/Test folders/Test folder 1/File test 1.rtf:/Users/phil/Test folders/Test folder 1/File test 2.rtf"

set AppleScript's text item delimiters to ":"
set _paths to text items of _pathsString
set AppleScript's text item delimiters to ""

set _fileStrings to {}
repeat with _path in _paths
    set end of _fileStrings to POSIX file _path as text
end repeat

_fileStrings
-- Result: {"320 of 500:Users:phil:Test folders:Test folder 1:File test 1.rtf", "320 of 500:Users:phil:Test folders:Test folder 1:File test 2.rtf"}

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Jun 30, 2011

Indirect object is a text or a list of texts when its paths, thx all:

on process text dObject with iObject
  activate
  set message to "Direct is '" & dObject & "'"
  if class of iObject is list then
    set message to message & " indirect has " & (number of items in iObject) & " items:"
    repeat with i from 1 to number of items in iObject
      set message to message & return & tab & quote & (item i of iObject) & quote
    end repeat
  else if class of iObject is text then
    set message to message & " indirect is '" & iObject & "'"
  end if
  display dialog message buttons {"OK"} default button 1
end process text

(edit: formatting)

@philostein
Copy link
Contributor

@philostein philostein commented Jul 12, 2011

Any word on when (or if) this is going to be pushed?

I have a fighting chance of compiling the master, and then I can try this feature out. ;)

@clarkewd
Copy link

@clarkewd clarkewd commented Aug 18, 2011

Am I correct in thinking that until this gets pulled in to the master branch and a new version of QS is released then there is no way to access both a direct and indirect object with AS ? Even if they are just text? This seems like a very cool thing to have available. Is there any documentation or resources for it? So far this page has been the most helpful thing.

@skurfer
Copy link
Member

@skurfer skurfer commented Aug 20, 2011

Am I correct in thinking that until this gets pulled in to the master branch and a new version of QS is released then there is no way to access both a direct and indirect object with AS?

Well, there’s a way. How comfortable are you with Git and Xcode? ;)

I thought this was waiting on something additional, but perhaps not. I’ll look over the comments again and the code and see if there’s any reason not to merge it. And you’re correct that it’ll show up in the next release if I do.

@ddlsmurf
Copy link
Contributor Author

@ddlsmurf ddlsmurf commented Sep 10, 2011

I don't think this is waiting for anything more (or I am not aware of it so please point it out - and sorry in advance)

@clarkewd : Yes, this won't be in Quicksilver until this is pulled in. Also note the code sample changed during the chat . As skurfer said though, you can build your own: build procedures documented here . Though I am unaware of any issues that would prevent this being pulled in at some point down the road.

@skurfer
Copy link
Member

@skurfer skurfer commented Sep 11, 2011

I don't think this is waiting for anything more (or I am not aware of it so please point it out - and sorry in advance)

It’ll feel good to do something, so yeah, maybe I’ll actually do what I said I’d do a month ago and see if there’s anything outstanding. :)

While I don’t use the specific features introduced, I have been running with this code ever since it appeared without issue.

skurfer added a commit that referenced this issue Sep 11, 2011
…bject

Add indirectobject parameter to AppleScript action handlers
@skurfer skurfer merged commit 505ace1 into quicksilver:master Sep 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants