Skip to content

Commit

Permalink
Refactor pyobjc dependency to use AppleScript instead. Add build on e…
Browse files Browse the repository at this point in the history
…very push.
  • Loading branch information
cleobis committed Apr 11, 2022
1 parent 3d8cf55 commit b02de90
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 26 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Create Alfred Workflow

on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Move info.plist to expected location
run: mv src/info.plist .

- name: Build Alfred Workflow
id: alfred_builder
uses: mperezi/build-alfred-workflow@v1
with:
workflow_dir: src
exclude_patterns: '*.pyc *__pycache__/*'

- name: Archive plugin
uses: actions/upload-artifact@v3
with:
name: plugin
path: ${{ steps.alfred_builder.outputs.workflow_file }}
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
*.pyc
.DS_Store
pyobjc
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ Original repo: [owenwater/alfred-cal](https://github.com/owenwater/alfred-cal)

Updates from: [oorahduc/alfred-cal](https://github.com/oorahduc/alfred-cal) for fixes to the "Incompatible with macOS Sierra 10.12.4+" issue.

[This repo](https://github.com/cleobis/alfred-cal) fixes a crash on macOS Big Sur 11.1 and formatting issues.
[This repo](https://github.com/cleobis/alfred-cal) supports macOS 12.3 Monterey. Python3 must be installed by the user.

## Calendar

Displays a monthly calendar with Alfred Workflow.

## Install
- Have access to the Alfred [Powerpack](http://www.alfredapp.com/powerpack/).
- Install [python3](https://www.python.org/downloads/).
- Download Calendar-<version>.alfredworkflow from the [lastest release](https://github.com/cleobis/alfred-cal/releases/latest).
- Open the file. Alfred will automatically install it.

Expand All @@ -33,7 +34,7 @@ Displays a monthly calendar with Alfred Workflow.
- OS X Calendar

## Format
The workflow should automatically adapt to the current theme font.
~~The workflow should automatically adapt to the current theme font.~~ Automatic formatting not currently supported.

## Screenshots
![screenshot1](screenshots/screenshot1.png?raw=true)
Expand Down
29 changes: 15 additions & 14 deletions src/format.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/python
# encoding: utf-8

import json
import plistlib
import sys
#import tkFont
#import Tkinter as tk
import subprocess

# from AppKit import (
# NSFont,
# NSFontAttributeName,
Expand All @@ -15,6 +14,7 @@
# NSMutableDictionary,
# NSString
# )
import subprocess

plist = "/preferences/appearance/prefs.plist"
theme = "theme.plist"
Expand Down Expand Up @@ -42,16 +42,6 @@ def __init__(self, font, size):
def measure(self, _str):
return len(_str)

class FontWidthCalcApp(object):
def __init__(self, font, size):
self.font = font
self.size = size

def measure(self, _str):
status = subprocess.run(["./Font Width", self.font, str(self.size), _str], capture_output=True, check=True, text=True)
out = status.stdout.strip()
return float(out)

class FontWidthCalcObjC(object):
"""Calculate the display width of strings using the PyObjC bridge."""

Expand Down Expand Up @@ -101,7 +91,8 @@ def _load_font(self, theme_uid, preference_path):

self.log and self.log.info("Font: {} {}pt".format(font, size))

return FontWidthCalcApp(font, size)
return (font, size)
# return FontWidthCalcObjC(font, size)

def theme_path_from_id(self, theme_uid, preference_path):
"""Return the path to the them file for a theme uid.
Expand Down Expand Up @@ -171,7 +162,6 @@ def read_theme_font_name_size(self, theme_path):
str: The font name. ??? for the default system font.
float: The font size
"""
import json

f = open(theme_path, "r")
theme_data = json.load(f)
Expand All @@ -185,6 +175,8 @@ def read_theme_font_name_size(self, theme_path):
return font, size

def format(self, weeks, title):
return self.formatApp(weeks, title)

pos = [self.font.measure(title[:title.find(day)+len(day)]) for day in title.split()]
space = '\u200a' # hair space
space_width = self.font.measure(space)
Expand All @@ -197,6 +189,15 @@ def format(self, weeks, title):
str += day
str_list.append(str)
return str_list

def formatApp(self, weeks, title):
# status = subprocess.run(["./Font Width", self.font[0], str(self.font[1]), title, json.dumps(weeks)],
status = subprocess.run(["osascript", "./textWidth.scpt", self.font[0], str(self.font[1]), title, json.dumps(weeks)],
capture_output=True, check=True, text=True)
out = status.stdout
out = out.split("\n")
out = [x for x in out if len(x) > 0]
return out


if __name__ == "__main__":
Expand Down
18 changes: 9 additions & 9 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>/usr/bin/python main.py "{query}"</string>
<string>/usr/bin/env python3 main.py "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -100,7 +100,7 @@
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>/usr/bin/python open.py "{query}"</string>
<string>/usr/bin/env python3 open.py "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -143,7 +143,7 @@
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>/usr/bin/python config.py "{query}"</string>
<string>/usr/bin/env python3 config.py "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -172,7 +172,7 @@
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>/usr/bin/python config.py -set "{query}"</string>
<string>/usr/bin/env python3 config.py -set "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand All @@ -196,12 +196,15 @@ Original repo: [owenwater/alfred-cal](https://github.com/owenwater/alfred-cal)
Updates from: [oorahduc/alfred-cal](https://github.com/oorahduc/alfred-cal) for fixes to the "Incompatible with macOS Sierra 10.12.4+" issue.
[This repo](https://github.com/cleobis/alfred-cal) fixes a crash on macOS Big Sur 11.1 and formatting issues.
[This repo](https://github.com/cleobis/alfred-cal) supports macOS 12.3 Monterey. Python3 must be installed by the user.
## Calendar
Displays a monthly calendar with Alfred Workflow.
## Install
- You must have [python3](https://www.python.org/downloads/) installed and on your path.
## Usage
- `cal [month [year]] [&lt;] [&gt;]`
- `↕` Choose a week.
Expand All @@ -216,9 +219,6 @@ Displays a monthly calendar with Alfred Workflow.
- Fantastical 2
- Google Calendar
- OS X Calendar
## Format
The workflow should automatically adapt to the current theme font.
</string>
<key>uidata</key>
<dict>
Expand Down Expand Up @@ -254,7 +254,7 @@ The workflow should automatically adapt to the current theme font.
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.5.3</string>
<string>1.6.0</string>
<key>webaddress</key>
<string>https://github.com/cleobis/alfred-cal</string>
</dict>
Expand Down
Binary file added src/textWidth.scpt
Binary file not shown.
2 changes: 1 addition & 1 deletion src/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.3
1.6.0

0 comments on commit b02de90

Please sign in to comment.