Postr supports Lua plugins that can be installed at ~/Library/Application Support/Postr/Plugins/. The plugins are plain-text files that have a “.lua” file extension.

Postr enables these objects in the Lua environment:

In addition, Postr enables these classes:

The *ArrayController objects correspond to NSArrayControllers and posts and services are NSManagedObjects.

Post objects have the following keys:

Service objects have the following keys:

Scheme objects are simple and only have three components. They define the keys and values for Service APIs.

Code samples

Here are a few small samples of using the above objects within Lua. More complex interactions are possible and the information passed to the Lua environment may be changed in the future.

-- Reverse the title of the selected post
x = SelectedPost:valueForKey("title")
rev = ""
j = string.len(x)
-- Lua v5.0.4 does not have string.reverse().  Will update Lua when framework is updated.
for i=1,j do rev = rev..string.sub(x, j-i+1, j-i+1) end
SelectedPost:setValue_forKey_(rev, "title")

-- Iterate over every post and print the title to stdout
postArray = PostArrayController:content()
e = postArray:objectEnumerator()
post = e:nextObject()
while post do
    print(post:valueForKey("title"))
    post = e:nextObject()
end

-- Create new post
post = Post:post()
post:setValue_forKey_("This post created in Lua", "title")
post:setValue_forKey_("http://www.lua.org", "url")
post:setValue_forKey_("Created on "..os.date()..".", "desc")
post:setValue_forKey_("lua plugin", "tags")

serviceArray = ServiceArrayController:content()
if serviceArray:count() > 0 then
    firstService = serviceArray:objectAtIndex(0)
    post:setValue_forKey_(firstService, "service")
end

-- Write service information to Desktop
-- Demonstrates working with services, schemes, and simple io
local f = assert(io.open(os.getenv("HOME").."/Desktop/Postr services.txt", "w+"))
f:write("File created on "..os.date().."\n------------------------------------------\n\n")
serviceArray = ServiceArrayController:content()
e = serviceArray:objectEnumerator()
service = e:nextObject()
while service do
    name = service:valueForKey("name")
    url = service:valueForKey("url")
    apiUrl = service:valueForKey("api_url")
    protocol = service:valueForKey("protocol")

    if (name) then f:write(string.format("%s ", name)) end
    if (url) then f:write(string.format("<%s> ", url)) end
    if (apiUrl) then f:write(string.format("\n\t%s", apiUrl)) end
    if (protocol) then f:write(string.format(" (%s)", protocol)) end

    schemeSet = service:mutableSetValueForKey("scheme")
    if (schemeSet) then f:write("\n") end

    sse = schemeSet:objectEnumerator()
    scheme = sse:nextObject()
    while scheme do
        f:write(string.format("\t%s = %s\n", scheme:valueForKey("key"), scheme:valueForKey("value")))
        scheme = sse:nextObject()
    end

    f:write("\n\n")
    service = e:nextObject()
end
f:close()
Postr makes use of the LuaObjCBridge.