Created
March 13, 2017 09:47
-
-
Save AndrewHazelden/b9909520490624305183f7c8f77368a2 to your computer and use it in GitHub Desktop.
A Blackmagic Design Fusion LUA script example to copy items into the clipboard using xclip (Linux), clip (Windows), and pbcopy (macOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------------------------ | |
-- Copy to Clipboard Script for Fusion - 2017-03-13 06.27 AM | |
-- by Andrew Hazelden | |
-- www.andrewhazelden.com | |
-- [email protected] | |
------------------------------------------------------------------------------ | |
-- Display the extra debugging verbosity detail in the console log | |
printStatus = true | |
-- printStatus = false | |
-- Find out if we are running Fusion 6, 7, or 8 | |
local fu_major_version = math.floor(tonumber(eyeon._VERSION)) | |
-- Find out the current operating system platform. The platform local variable should be set to either 'Windows', 'Mac', or 'Linux'. | |
local platform = '' | |
if string.find(comp:MapPath('Fusion:\\'), 'Program Files', 1) then | |
-- Check if the OS is Windows by searching for the Program Files folder | |
platform = 'Windows' | |
elseif string.find(comp:MapPath('Fusion:\\'), 'PROGRA~1', 1) then | |
-- Check if the OS is Windows by searching for the Program Files folder | |
platform = 'Windows' | |
elseif string.find(comp:MapPath('Fusion:\\'), 'Applications', 1) then | |
-- Check if the OS is Mac by searching for the Applications folder | |
platform = 'Mac' | |
else | |
platform = 'Linux' | |
end | |
-- Copy text to the operating system's clipboard | |
-- Example: CopyToClipboard('Hello World!') | |
function CopyToClipboard(textString) | |
-- The system temporary directory path (Example: $TEMP/DomemasterFusionMacros/) | |
outputDirectory = comp:MapPath('Temp:\\DomemasterFusionMacros\\') | |
clipboardTempFile = outputDirectory .. 'ClipboardText.txt' | |
-- Create the temp folder if required | |
os.execute('mkdir "' .. outputDirectory..'"') | |
-- Open up the file pointer for the output textfile | |
outClipFile, err = io.open(clipboardTempFile,'w') | |
if err then | |
print("[Error Opening Clipboard Temporary File for Writing]") | |
return | |
end | |
outClipFile:write(textString,'\n') | |
-- Close the file pointer on the output textfile | |
outClipFile:close() | |
if platform == 'Windows' then | |
-- The Windows copy to clipboard command is "clip" | |
command = 'clip < "' .. clipboardTempFile .. '"' | |
elseif platform == 'Mac' then | |
-- The Mac copy to clipboard command is "pbcopy" | |
command = 'pbcopy < "' .. clipboardTempFile .. '"' | |
elseif platform == 'Linux' then | |
-- The Linux copy to clipboard command is "xclip" | |
-- This requires a custom xclip tool install on Linux: | |
-- Debian/Ubuntu: | |
-- sudo apt-get install xclip | |
-- Redhat/Centos/Fedora: | |
-- yum install xclip | |
command = 'cat "' .. clipboardTempFile .. '" | xclip -selection clipboard &' | |
end | |
if printStatus == 1 or printStatus == true then | |
print('[Copy Text to Clipboard Command] ' .. command) | |
print('[Clipboard] ' .. textString) | |
end | |
os.execute(command) | |
end | |
------------------------------------------------------------------------------ | |
------------------------------------------------------------------------------ | |
-- Copy Text to the clipboard | |
-- CopyToClipboard('Hello World!') | |
-- Copy the selected Loader node filepath to the clipboard | |
selectedNode = comp.ActiveTool | |
CopyToClipboard(selectedNode.Output[comp.CurrentTime].Metadata.Filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment