0

I would like to be able to select an item on my desktop and type a shortcut to attach the selected item to a new message with the Messages app. I've tried to create one in system preferences/keyboard/keyboard shortcuts/Application Shortcuts under Finder.app typed "Share>Message" and it didn't work. I have a shortcut to "new email with selection" that I created with automator but Messages is not an option there. I also tried searching for an Applescript or terminal command for this so I could do it with a swipe gesture using Better Touch Tool. I spoke with an Apple senior advisor and he said he didn't know how to do it either and to post it on the forums.

If anyone knows how to make a shortcut for this action, please let me know.

update: I copied this from /System/Library/PrivateFrameworks/ShareKit.Framework/Versions/A/Plugins/Message s.sharingservice/Contents/MacOS

If anyone knows if this line can be turned into a .service with automator, Please let me know how to do/modify it.

Thanks

/System/Library/PrivateFrameworks/ShareKit.framework/Versions/A/PlugIns/Messages .sharingservice/Contents/MacOS/Messages ; exit; NAME-Mac:~ NAME$ /System/Library/PrivateFrameworks/ShareKit.framework/Versions/A/PlugIns/Message s.sharingservice/Contents/MacOS/Messages ; exit; -bash: /System/Library/PrivateFrameworks/ShareKit.framework/Versions/A/PlugIns/Message s.sharingservice/Contents/MacOS/Messages

-- 

delay 0.218623 set timeoutSeconds to 2.000000 set uiScript to "click image \"Test File\" of group 1 of scroll area 1 of application process \"Finder\"" my doWithTimeout( uiScript, timeoutSeconds )

-- Message delay 0.263641 set timeoutSeconds to 2.000000 set uiScript to "click menu item \"Message\" of menu 1 of menu item \"Share\" of menu 1 of group 1 of scroll area 1 of application process \"Finder\"" my doWithTimeout( uiScript, timeoutSeconds )

on doWithTimeout(uiScript, timeoutSeconds) set endDate to (current date) + timeoutSeconds repeat try run script "tell application \"System Events\" " & uiScript & " end tell" exit repeat on error errorMessage if ((current date) > endDate) then error "Can not " & uiScript end if end try end repeat end doWithTimeout

Elias
  • 91
  • 1
  • 8

1 Answers1

0

I cannot see how to get those to run.

You could setup an Automator Service with its input set to files and folders in"Finder"

and use this code in a Run Applescript Action.

It works But the main thing that was an issue was getting the correct buddy. I have set it so you can choose the one you want. More work could be done I expect to let you type a name and it returns the smaller list of matching names and handles.

on run {input, parameters}

    set buddieList to {}
    set splitter to "======"
    tell application "Messages"
        --set buddieList to {name of buddies, handle of buddies}
        repeat with i from 1 to number of items in buddies
            set this_item to item i of buddies
            copy (name of this_item as string) & splitter & handle of this_item as string to end of buddieList

        end repeat
    end tell


    set inputAlias to item 1 of input as alias

    set text_returned to item 1 of (choose from list buddieList with prompt "TO:" without multiple selections allowed and empty selection allowed)
    set theBuddy to (do shell script "echo  " & quoted form of text_returned & " | awk -F" & splitter & " '{print $2}'")
    tell application "Messages"
        set theBuddy to first buddy whose handle is theBuddy

        send inputAlias to theBuddy

    end tell

end run

**UPDATE.

In answer to your comments: I did not actually use the search field in the finder share. So it was nice to see it was actually structued the same way I structured my chooser. :-)

But it seems it is searching you contacts rather than the Buddy list.

So this new script uses a search of for contact names which contains any text you enter. And just like the real share. There is no guarantee that the persons number or email will be linked to iMessages their end.

Also note I put this together in a few minutes. So its not as tidy as it could be. but It gives you something to play with.

on run {input, parameters}

    set buddieList to {}
    set splitter to "======"
    tell application "Messages"
        activate
        display dialog "Name Contains.." default answer "" buttons {"Cancel", "OK"} default button 2
        copy the result as list to {text_returned, button_pressed}

    end tell
    tell application "Contacts"

        set buddies to people whose name contains text_returned

        repeat with a from 1 to number of items in buddies

            set this_name to name of item a of buddies
            set this_email to email of item a of buddies
            set this_phone to phone of item a of buddies
            repeat with e from 1 to number of items in this_email

                set this_email_item to item e of this_email
                if this_email_item is not {} then
                    copy (this_name) & splitter & value of this_email_item as string to end of buddieList
                end if
            end repeat

            repeat with e from 1 to number of items in this_phone

                set this_iphone_item to item e of this_phone
                if this_iphone_item is not {} then
                    copy (this_name) & splitter & value of this_iphone_item as string to end of buddieList
                end if
            end repeat

        end repeat
    end tell

    tell application "Messages" to set text_returned to item 1 of (choose from list buddieList with prompt "TO:" without multiple selections allowed and empty selection allowed)

    set inputAlias to item 1 of input as alias

    set theBuddy to (do shell script "echo  " & quoted form of text_returned & " | awk -F" & splitter & " '{print $2}'")
    tell application "Messages"
        try
            set findBuddy to first buddy whose handle is theBuddy


            send inputAlias to findBuddy
        on error
             display dialog "NO BUDDY Found with " & theBuddy
        end try
    end tell

end run

It is meant to be put into a Run Applescript Action in Automator. As a Service. Copy and paste it replacing all the default code.

enter image description here

markhunte
  • 6,805
  • 2
  • 25
  • 44
  • It only shows the first two buddies though. Is there a way to show the Messages popup to search for a buddy? – Elias Dec 14 '12 at 23:52
  • Thanks for helping me with this. I tried it and it opens Messages but does not send the selected file. Is there a way to select the right click menu item "Share>Messages" via a service with Automator using a shell script? – Elias Dec 17 '12 at 02:29
  • It is meant to be put into a Run Applescript Action in Automator. As a Service. Copy and paste it replacing all the default code. I just tested it again here and it works. See image I have just attached. – markhunte Dec 17 '12 at 06:56
  • I followed the instructions and it opens iMessage in the background. When I bring it to front, the "Name Contains.." window appears. I type in the email address of the buddy, the Contacts Application launches and it gives me this error : "The action “Run AppleScript” encountered an error." – Elias Dec 18 '12 at 08:56
  • Sorry, I just noticed a typo in the script I posted. I had 'if this_iphone_item is not {} then' instead of ' if this_email_item is not {} then'. The Script is now updated. Remember you will need to save the device and run it when control clicking a file and going to services. – markhunte Dec 18 '12 at 19:52
  • I tried the new script after deleting the iMessage plist and it still does the same thing. The original script works, it opens the contacts window in the front and sends the selected file. The only thing is that you can not choose whom to send it to. I appreciate all the time that you have put into this. I found the "MacOS" file in /System/Library/PrivateFrameworks/ShareKit.framework/Versions/A/PlugIns/Messages.sharingservice/Contents/MacOS/Messages. Is there any way I can select a file and execute this to attach it to iMessage just like selecting a file and right clicking Share>Message? – Elias Dec 19 '12 at 05:11
  • Very strange. What OS X are you on. Because it works here with no issue. 10.8.2. As to the MacOS file. I tried that and could not get it to work. There is a "System/Library/PrivateFrameworks/ShareKit.framework/Versions/A/XPCServices/com.apple.ShareKitHelper.xpc/Contents/MacOS/com.apple.ShareKitHelper" which I got some response but could not get to work – markhunte Dec 19 '12 at 07:17
  • Currently I am on Mac OS 10.8.2 12C60,I tried it on a new account and it did open it in the front. It didn't send so I was wandering if it mattered that this account does not have any contacts, does this script require an entry in Contacts to be able to send it? I copied this from Console after trying it in my regular account:12/20/12 5:29:31.634 AM Messages[10872]: Performance: Please update this scripting addition to supply a value for ThreadSafe for each event handler: "/Library/ScriptingAdditions/SIMBL.osax" – Elias Dec 20 '12 at 10:57
  • Yes. As I said it searches your contacts. in (Caontacts.app) You pick a person and its matching contact info. Then it asks Messages to look for a matching buddy. If it finds one it will try and send it. If not it will tell it did not find a buddy. BUT you do need you contacts to be populated. – markhunte Dec 20 '12 at 22:01
  • Do you think that this has something to do with the "Simbl" that was mentioned in the Console. I use Lion Designer.App to change the sidebar icons to colorful instead of grey. It requires SIMBL. I noticed that after running the script, the icons are grey now. I tried to uninstall the colorful icons but had the same result. – Elias Dec 21 '12 at 08:01
  • I cannot say. It is unlikely. Have you added any contacts and tried it?? – markhunte Dec 21 '12 at 18:54
  • By the way why dont you update the osax /Library/ScriptingAdditions/ – markhunte Dec 21 '12 at 18:56
  • I went to the SIMBL developers site and I have the newest version. It still does the same thing with contacts added. I recorded right clicking and choosing share>Message with watch me do on automator. These can be pasted in apple script editor and executed. Do you know if you could sort out this script to "choose" Share>Message? This could be a service created with Automator to "run AppleScript" – Elias Dec 22 '12 at 23:48
  • At the bottom of the original edit is the Watch Me Do paste for shortcut to Apple Share. – Elias Dec 22 '12 at 23:57
  • That was one of the first things I tried before I wrote the script. It does not work – markhunte Dec 23 '12 at 01:02
  • I really like the Apple original Share>Message functionality. Since there doesn't seem to be a way to create a custom shortcut for this in System Preferences/Keyboard/Keyboard Shortcuts/Application Shortcuts/Finder.App. Is there a way to modify the com.apple.universalaccess.plist to have the ability to do this? When I change this part of System Prefs, this is the plist where it is stored. – Elias Dec 23 '12 at 04:54