Vojta Holik

Vojta Holik

defaults write com.apple.screencapture location ~/Desktop/screenshots
// Name: Watch Screenshots Dir
// Watch: ~/Desktop/screenshots
// Description: Don't forget to run following command in your terminal to set default screenshot directory in macOSX: defaults write com.apple.screencapture location ~/Desktop/screenshots
import "@johnlindquist/kit";
import cloudinary from "cloudinary";
import trash from "trash";
const DIR = "screenshots";
const NOTIFY_SOUND_FILE_PATH = false; // home("Desktop/come-here-notification.mp3");
const CUSTOM_DOMAIN = false; // 'https://vojta.io/shots/'
// These are optional and automatically set by the watcher
let filePath = await arg();
let event = await arg();
// Cloudinary options
const options = {
public_id: `${DIR}/${Date.now()}`,
unique_filename: true,
use_filename: true,
overwrite: true,
filename_override: true,
};
cloudinary.v2.config({
cloud_name: await env("CLOUDINARY_CLOUD_NAME"),
api_key: await env("CLOUDINARY_API_KEY"),
api_secret: await env("CLOUDINARY_API_SECRET"),
});
// if file is added to DIR directory
if (event === "add") {
await appendFile(home(`Desktop/${DIR}/download.log`), filePath + "\n");
const isVideoFile = filePath.endsWith(".mov");
await cloudinary.v2.uploader.upload(
filePath,
{ ...options, resource_type: isVideoFile ? "video" : "image" },
async (error, result) => {
if (error) {
console.error("Error uploading file:", error);
} else {
if (result) {
await copy(
CUSTOM_DOMAIN
? `${CUSTOM_DOMAIN}${result.public_id.replace(`${DIR}/`, "")}`
: isVideoFile
? result.url.replace(".mov", ".mp4")
: result.url
);
notify("✓ Uploaded to Cloudinary");
NOTIFY_SOUND_FILE_PATH &&
(await playAudioFile(NOTIFY_SOUND_FILE_PATH));
await trash([filePath]);
}
}
}
);
}

// Menu: Record Screen
// Shortcut: shift cmd 5
/** @type {import("@johnlindquist/kit")} */
await applescript(`
-- # Setup to do a screen recording.
# tell application "QuickTime Player" to new screen recording
-- # Start the screen recording.
tell application "System Events" to tell process "Screen Shot"
repeat until exists button "Record" of its front window
delay 0.1
end repeat
click button "Record" of its front window
end tell
-- # Set the time in seconds you want the recording to be.
delay 2
-- # Stop the recording.
tell application "System Events" to ¬
click menu bar item 1 ¬
of menu bar 1 ¬
of application process "screencaptureui"
`);