Commits

Bob Ippolito committed 44b45af

tweaks to try and get Mail to work with it, but no luck. Mail sucks.

Comments (0)

Files changed (4)

Examples/00ReadMe.html

 </ul>
 <ul>
 <li><a href="AppKit/TinyURLService">TinyURLService</a><p>Another simple service, this one converts URL or strings from the
-pasteboard to tinyurl.com equivalents (shift-cmd-V by default).</p>
+pasteboard to tinyurl.com equivalents.</p>
 </li>
 </ul>
 <ul>

Examples/00ReadMe.txt

 * `TinyURLService`__
 
   Another simple service, this one converts URL or strings from the
-  pasteboard to tinyurl.com equivalents (shift-cmd-V by default).
+  pasteboard to tinyurl.com equivalents.
 
 .. __: AppKit/TinyURLService
   

Examples/AppKit/TinyURLService/TinyURLService.py

 
 class TinyURLService(NSObject):
     def doTinyURLService_userData_error_(self, pboard, data):
+        # Mail.app in 10.4.1 doesn't do NSURLPboardType correctly!
+        # Probably elsewhere too, so we just use strings.
         try:
-            types = [NSURLPboardType, NSStringPboardType]
-            destType = pboard.availableTypeFromArray_(types)
-            if destType is None:
-                return ERROR(NSLocalizedString(
-                        "Error: Pasteboard doesn't contain a string.",
-                        "Pasteboard couldn't give string."
+            #NSLog(u'doTinyURLService: %r' % (pboard,))
+            types = pboard.types()
+            url = None
+
+            
+            if NSStringPboardType in types:
+                #NSLog(u'getting NSStringPboardType')
+                urlString = pboard.stringForType_(NSStringPboardType)
+                #NSLog(u'NSStringPboardType: %r' % (urlString,))
+                url = NSURL.URLWithString_(urlString.strip())
+                if url is None:
+                    #NSLog(u'urlString was %r' % (urlString,))
+                    return ERROR(NSLocalizedString(
+                        "Error: Given URL was not well-formed.",
+                        "Given URL not well-formed."
                     ))
 
-            if destType == NSStringPboardType:
-                urlString = pboard.stringForType_(destType)
-                url = NSURL.URLWithString_(urlString.strip())
-            else:
-                url = NSURL.URLFromPasteboard_(pboard)
+            if url is None:
+                return ERROR(NSLocalizedString(
+                        "Error: Pasteboard doesn't contain a valid URL.",
+                        "Pasteboard doesn't contain a valid URL.",
+                    ))
+
 
             urlString = url.absoluteString()
+            #NSLog(u'urlString = %r' % (urlString,))
             
             res = getTinyURL(urlString.UTF8String())
 
+            #NSLog(u'res = %r' % (res,))
             resURL = NSURL.URLWithString_(res)
+            #NSLog(u'resURL = %r' % (resURL,))
             if resURL is None:
+                NSLog(u'res was %r' % (res,))
                 return ERROR(NSLocalizedString(
                     "Error: Resultant URL was not well-formed.",
-                    "URL not well-formed."
+                    "Resultant URL not well-formed."
                 ))
-            pboard.declareTypes_owner_(types, None)
-            resURL.writeToPasteboard_(pboard)
-            pboard.setString_forType_(res, NSStringPboardType)
+            pboard.declareTypes_owner_([NSStringPboardType], None)
+            pboard.setString_forType_(resURL.absoluteString(), NSStringPboardType)
             return ERROR(None)
         except:
             traceback.print_exc()

Examples/AppKit/TinyURLService/setup.py

     NSServices = [
         dict(
             NSKeyEquivalent=dict(
-                default=u'F',
-            ),
-            NSMenuItem=dict(
-                default=u'Open File',
-            ),
-            NSMessage=u'doOpenFileService',
-            NSPortName=u'TinyURLService',
-            NSSendTypes=[
-                u'NSStringPboardType',
-            ],
-        ),
-        dict(
-            NSKeyEquivalent=dict(
-                default=u'V',
+                default=u'0',
             ),
             NSMenuItem=dict(
                 default=u'Shorten URL'
             NSMessage=u'doTinyURLService',
             NSPortName=u'TinyURLService',
             NSReturnTypes=[
-                u'NSURLPboardType',
                 u'NSStringPboardType',
             ],
             NSSendTypes=[
-                u'NSURLPboardType',
                 u'NSStringPboardType',
             ],
         ),