Skip to content

Instantly share code, notes, and snippets.

@kch
Created August 19, 2010 04:50
Show Gist options
  • Save kch/537075 to your computer and use it in GitHub Desktop.
Save kch/537075 to your computer and use it in GitHub Desktop.
n00b attempt at standalone foundation tool OS X service in MacRuby
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key> <string>English</string>
<key>CFBundleExecutable</key> <string>upcase</string>
<key>CFBundleIdentifier</key> <string>com.caiochassot.services.upcase</string>
<key>CFBundleInfoDictionaryVersion</key> <string>6.0</string>
<key>CFBundlePackageType</key> <string>BNDL</string>
<key>CFBundleShortVersionString</key> <string>1.0</string>
<key>CFBundleSignature</key> <string>????</string>
<key>CFBundleVersion</key> <string>1</string>
<key>NSUIElement</key> <string>1</string>
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key> <dict><key >default</key><string>Upcase</string></dict>
<key>NSMessage</key> <string >upcase</string>
<key>NSPortName</key> <string >Upcase</string>
<key>NSReturnTypes</key> <array><string>public.utf8-plain-text</string></array>
<key>NSSendTypes</key> <array><string>public.utf8-plain-text</string></array>
</dict>
</array>
</dict>
</plist>
// #import <objc/objc-auto.h>
// #import <Foundation/Foundation.h>
extern int NuMain(int argc, const char *argv[]);
int main(int argc, const char *argv[])
{
return NuMain(argc, argv);
}
task :default do
system %[
rm -rf Upcase.service rb/upcase.o ~/Library/Services/Upcase.service
macrubyc -V -o upcase rb/upcase.rb
rm -f rb/upcase.o
mkdir -p Upcase.service/Contents/MacOS
cp Info.plist Upcase.service/Contents/
mv upcase Upcase.service/Contents/MacOS/
mv Upcase.service ~/Library/Services/
/System/Library/CoreServices/pbs
]
end
task :nu do
system %[
rm -rf upcase Upcase.service ~/Library/Services/Upcase.service
llvm-gcc nu/main.m -framework Nu -fobjc-gc-only -o upcase
mkdir -p Upcase.service/Contents/MacOS Upcase.service/Contents/Resources
cp Info.plist Upcase.service/Contents/
cp nu/upcase.nu Upcase.service/Contents/Resources/main.nu
mv upcase Upcase.service/Contents/MacOS/
mv Upcase.service ~/Library/Services/
/System/Library/CoreServices/pbs
]
end
(import "Appkit")
(class KCUpcase is NSObject
(imethod (void) upcase: (id) pasteboard userData: (id) s_userData error: (id) s_error is
(let (s ((pasteboard stringForType:"public.utf8-plain-text") uppercaseString))
(pasteboard clearContents)
(pasteboard setString: s forType:"public.utf8-plain-text"))))
(NSRegisterServicesProvider ((KCUpcase alloc) init) "Upcase")
((NSRunLoop currentRunLoop) runUntilDate:(NSDate dateWithTimeIntervalSinceNow:10.0))
; ((NSRunLoop currentRunLoop)
; acceptInputForMode:NSDefaultRunLoopMode
; beforeDate:(NSDate dateWithTimeIntervalSinceNow:10.0))
#!/usr/local/bin/macruby
# encoding: UTF-8
framework 'Foundation'
framework 'Appkit'
class KCUpcase
def upcase(pasteboard, userData: s_userdata, error: s_error)
pasteboard.stringForType("public.utf8-plain-text").upcase.tap do |s|
pasteboard.clearContents
pasteboard.setString(s, forType: "public.utf8-plain-text")
end
end
end
NSLog "Starting…"
NSRegisterServicesProvider(KCUpcase.new, "Upcase")
NSLog "Registered…"
# NSRunLoop.currentRunLoop.acceptInputForMode NSDefaultRunLoopMode, beforeDate: NSDate.dateWithTimeIntervalSinceNow(20.0)
NSRunLoop.currentRunLoop.runUntilDate NSDate.dateWithTimeIntervalSinceNow(60.0)
NSLog "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment