AutomatorでPDFをシャッフルしたい
PDFをシャッフルして結合したいのですが、エラー6が表示されて結合できません。
OSはVenturaです。
MacBook Air (2018 – 2020)
Apple の脅威の通知と金銭目当てのスパイウェアへの対策について
Apple の脅威の通知と金銭目当てのスパイウェアへの対策についてが公開されました。
Apple の脅威の通知と金銭目当てのスパイウェアへの対策についてが公開されました。
PDFをシャッフルして結合したいのですが、エラー6が表示されて結合できません。
OSはVenturaです。
MacBook Air (2018 – 2020)
こんな感じの Automator クイックアクションでどうでしょうか。当方ではこれで大丈夫です。
コード
'use strict';
ObjC.import('Cocoa');
ObjC.import('PDFKit');
function setfname() {
const df = $.NSDateFormatter.alloc.init;
df.locale = $.NSLocale.localeWithLocaleIdentifier('en_US_POSIX');
df.dateFormat = 'yyyyMMddHHmmss';
const now = df.stringFromDate($.NSDate.date).js;
return `${now}.pdf`;
}
function makedocs(argv) {
const docs = [];
const pp = [];
for (const f of argv) {
const furl = $.NSURL.fileURLWithPath(f);
const doc = $.PDFDocument.alloc.initWithURL(furl);
docs.push(doc);
pp.push(Number(doc.pageCount));
}
const max = pp.reduce((a, b) => Math.max(a, b), -Infinity);
return {docs, max}
}
function run(argv) {
argv = argv.map(x => x.toString());
const {docs, max} = makedocs(argv);
const pdf = $.PDFDocument.alloc.init;
let idx = 0;
for (let i = 0; i < max; i++) {
for (const doc of docs) {
if (i < Number(doc.pageCount)) {
pdf.insertPageAtIndex(doc.pageAtIndex(i), idx++);
}
}
}
const dname = $(argv[0]).stringByDeletingLastPathComponent.js;
const fname = setfname();
const fpath = $(dname).stringByAppendingPathComponent(fname).js;
if (pdf.writeToFile(fpath)) {
return fpath;
} else {
throw new Error(`failed to write to file "${fpath}"`);
}
}
こんな感じの Automator クイックアクションでどうでしょうか。当方ではこれで大丈夫です。
コード
'use strict';
ObjC.import('Cocoa');
ObjC.import('PDFKit');
function setfname() {
const df = $.NSDateFormatter.alloc.init;
df.locale = $.NSLocale.localeWithLocaleIdentifier('en_US_POSIX');
df.dateFormat = 'yyyyMMddHHmmss';
const now = df.stringFromDate($.NSDate.date).js;
return `${now}.pdf`;
}
function makedocs(argv) {
const docs = [];
const pp = [];
for (const f of argv) {
const furl = $.NSURL.fileURLWithPath(f);
const doc = $.PDFDocument.alloc.initWithURL(furl);
docs.push(doc);
pp.push(Number(doc.pageCount));
}
const max = pp.reduce((a, b) => Math.max(a, b), -Infinity);
return {docs, max}
}
function run(argv) {
argv = argv.map(x => x.toString());
const {docs, max} = makedocs(argv);
const pdf = $.PDFDocument.alloc.init;
let idx = 0;
for (let i = 0; i < max; i++) {
for (const doc of docs) {
if (i < Number(doc.pageCount)) {
pdf.insertPageAtIndex(doc.pageAtIndex(i), idx++);
}
}
}
const dname = $(argv[0]).stringByDeletingLastPathComponent.js;
const fname = setfname();
const fpath = $(dname).stringByAppendingPathComponent(fname).js;
if (pdf.writeToFile(fpath)) {
return fpath;
} else {
throw new Error(`failed to write to file "${fpath}"`);
}
}
# このボードの不具合により回答が消えてしまったようなので再投稿します。(内容は前回と異なります)
まず、エラーについてですが、今朝の時点では Jennatoni さんと同様だったのですが、何かの拍子に正常に動くようになりました...。きっかけは分かりません...。とりあえず OS をセーフモードで起動し、立ち上がったら何もせず再起動してみる (これで諸々のキャッシュがクリアされる) と良いかもしれません。
次に、消えてしまったワークフローですが「PDFページを結合」アクションとはシャッフルの方法が異なるのでボツにしてください。で、セーフモードとかいろいろ試しても当該アクションが正常に動かないならその旨お知らせください。作り直したワークフローを投稿しなおします。
セーフモードでのキャッシュクリアを行いましたが、同じくエラー6が発生してしまいました…
できました!!!!!本当にありがとうございます;;
AutomatorでPDFをシャッフルしたい