Skip to content

Instantly share code, notes, and snippets.

View rok-git's full-sized avatar

rok rok-git

View GitHub Profile
@rok-git
rok-git / ocr.sh
Last active June 29, 2023 12:12 — forked from doraTeX/ocr.sh
A shell script to perform OCR on images/PDFs using macOS built-in OCR engine
#!/bin/bash
SCRIPTNAME=$(basename "$0")
function realpath () {
f=$@;
if [ -d "$f" ]; then
base="";
dir="$f";
else
base="/$(basename "$f")";
@rok-git
rok-git / monochro.m
Created February 8, 2022 13:37
make a grayscale image using CIFilter.
// To Compile: cc -fobjc-arc -framework Cocoa -framework CoreImage monochro.m -o monochro
#import <Cocoa/Cocoa.h>
#import <CoreImage/CoreImage.h>
#include <stdio.h>
void usage()
{
printf("Usage: argv[0] < INPUTFILE > OUTPUTFILE\n");
printf(" argv[0] INPUTFILE > OUTPUTFILE\n");
@rok-git
rok-git / randaom256x256.m
Created January 12, 2022 01:51
Sample of PhotoKit on macOS.
//To Compile: cc -fobjc-arc -framework Cocoa -framework Photos random256x256.m -o random256x256
#import <Cocoa/Cocoa.h>
#import <Photos/Photos.h>
#include <stdlib.h>
int main()
{
@autoreleasepool{
PHFetchResult *assets = [PHAsset fetchAssetsWithMediaType: PHAssetMediaTypeImage options: nil];
NSUInteger idx = arc4random() % assets.count;
#import <CoreLocation/CoreLocation.h>
#import <Foundation/Foundation.h>
// CoreLocation を使って住所から 経度・緯度を求める。
// 引数は住所。空白を含む場合はクオートすること。
// COMPILE: cc -fobjc-arc -framework Foundation -framework CoreLocation AddressToCoordinate.m -o AddressToCoordinate
int main(int argc, char *argv[])
{
@autoreleasepool{
__block int ret = 0;
@rok-git
rok-git / listEraSymbols.m
Last active April 3, 2019 06:46
(macOS) make a list of Japanese GENGO/日本の元号のリスト作る。
// Compile:
// cc -framework Foundation listEraSymbols.m -o listEraSymbols
// Usage: listEraSymbols [locale]
// Examples:
// listEraSymbols -- Gengo List in default Language (C locale)
// listEraSymbols ja_JP -- Gengo List in Japanese
// listEraSymbols zh_CN -- Gengo List in Chinese
// listEraSymbols en_US -- Gengo List in English
@rok-git
rok-git / Export_4K_Movies.applescript
Last active September 12, 2018 07:30
Export 4K movies taken with iPhone to other place using Photos.app and AppleScript.
tell application "Photos"
activate
tell album "動画" -- 「写真」が「ムービー」「である」スマートアルバム (Smart album that collect all movie files)
set outFolder to choose folder
set mvList to media items whose (width = 3840 or height = 3840)
export mvList to outFolder with using originals
end tell
end tell
@rok-git
rok-git / parseDateAndTime.m
Created February 22, 2018 06:23
parse a string as Date and Time in any format
// parse a date and time
#import <Foundation/Foundation.h>
int
main(int argc, char *argv[])
{
@autoreleasepool{
NSError *error = nil;
if(argc != 2){
@rok-git
rok-git / KeyAndValueOfAppleScriptsRecord.applescript
Created February 21, 2018 07:26
AppleScript の Record から、キーや値を個別に取り出す。
-- use AppleScript version "2.4"
-- use scripting additions
use framework "Foundation"
set aRec to {q:"hogbehoge", n:999} -- AppleScript's Record
-- create an instance of NSMutableDictionary
set aDic to current application's (NSMutableDictionary's dictionaryWithDictionary:aRec)
-- use NSMutableDictionary's methods
@rok-git
rok-git / reverseExcelsSheetOrder.applescript
Created February 6, 2018 06:40
Excel のワークシートを逆順に並び換える。
tell application "Microsoft Excel"
activate
set sheet_num to count sheets
repeat with i from 1 to sheet_num - 1
move sheet 1 to after sheet (sheet_num - i + 1)
end repeat
end tell
@rok-git
rok-git / openFoldersInTabsOfaWindow.applescript
Created February 5, 2018 06:10
Finder で新規のウィンドウを開いて、複数のフォルダをそのウィンドウのタブで開く。
set targetList to {"/Users/rok/tmp/", "/Users/rok/work/"}
tell application "Finder"
activate
set tabCount to count targetList
if tabCount ≥ 1 then
open (item 1 of targetList) as POSIX file
tell front window
repeat with i from 2 to tabCount