Skip to content

Instantly share code, notes, and snippets.

@prenagha
Last active February 26, 2024 07:02
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prenagha/8372844 to your computer and use it in GitHub Desktop.
Save prenagha/8372844 to your computer and use it in GitHub Desktop.
Launchbar integration applescript for command-c http://danilo.to/command-c/
--
-- Source: Padraic Renaghan prenagha@renaghan.com https://gist.github.com/prenagha/8372844
--
-- launchbar integration applescript for command-c
-- http://danilo.to/command-c/
--
-- set the variable "theDevice" below as needed to the device name you want to send to
-- Put script in Launchbar actions folder
-- ~/Library/Application Support/Launchbar/Actions
--
on urlencode(theText)
set theTextEnc to ""
repeat with eachChar in characters of theText
set useChar to eachChar
set eachCharNum to ASCII number of eachChar
if eachCharNum = 32 then
set useChar to "%20"
else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
set firstDig to round (eachCharNum / 16) rounding down
set secondDig to eachCharNum mod 16
if firstDig > 9 then
set aNum to firstDig + 55
set firstDig to ASCII character aNum
end if
if secondDig > 9 then
set aNum to secondDig + 55
set secondDig to ASCII character aNum
end if
set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
set useChar to numHex
end if
set theTextEnc to theTextEnc & useChar as string
end repeat
return theTextEnc
end urlencode
-- take string from LaunchBar and send to device
on handle_string(theText)
try
set theDevice to "iPhone"
set theURL to "command-c://x-callback-url/copyText?deviceName=" & urlencode(theDevice) & "&text=" & urlencode(theText)
tell application "System Events" to open location theURL
tell application "LaunchBar" to hide
on error e
tell application "LaunchBar" to display in large type "Error: " & e
end try
end handle_string
--take contents of a file (text) and send to device
on open (theFile)
try
set theDevice to "iPhone"
open for access theFile
set fileContents to (read theFile)
close access theFile
set theURL to "command-c://x-callback-url/copyText?deviceName=" & urlencode(theDevice) & "&text=" & urlencode(fileContents)
tell application "System Events" to open location theURL
tell application "LaunchBar" to hide
on error e
tell application "LaunchBar" to display in large type "Error: " & e
end try
end open
-- otherwise as straight action the send clipboard
try
set theDevice to "iPhone"
set theURL to "command-c://x-callback-url/copy?deviceName=" & urlencode(theDevice)
tell application "System Events" to open location theURL
tell application "LaunchBar" to hide
on error e
tell application "LaunchBar" to display in large type "Error: " & e
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment