Last active
July 24, 2025 03:29
-
-
Save ayman/cfbfc0b4ee3dbcc7f71fe9973249e4bc to your computer and use it in GitHub Desktop.
Lightroom Show Metadata for Instagram
This file contains hidden or 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
| --[[ | |
| Seeded from: http://lightroomsolutions.com/lightroom-to-instagram-via-a-web-browser/ | |
| Updated with ChatGPT | |
| SETUP INSTRUCTIONS: | |
| Temporarily save this file onto your desktop. | |
| Now you need to create a scripts folder: | |
| In Lightroom, choose Lightroom > Preferences (Mac OS) or Edit > Preferences (Windows). | |
| Choose the Preset tab and select "Show All Other Lightroom Presets" folder. | |
| Create a folder in the Lightroom folder called "Scripts". | |
| Uncomment the lines at the bottom that you want to customize the plugin. | |
| Copy this file into the Scripts folder. | |
| You should now have a new "Scripts" folder containing this file. | |
| Quit and reopen Lightroom. You should see a scripts menu next to the Help menu. | |
| --]] | |
| local LrTasks = require("LrTasks") | |
| local LrApplication = require("LrApplication") | |
| local LrDialogs = require("LrDialogs") | |
| local LrView = require("LrView") | |
| local catalog = LrApplication.activeCatalog() | |
| -- Utility function: splits a string by a pattern | |
| local function split(str, pat) | |
| local t = {} | |
| if str == nil or str == "" or type(str) == "table" then | |
| return { str } | |
| end | |
| local fpat = "(.-)" .. pat | |
| local last_end = 1 | |
| local s, e, cap = str:find(fpat, 1) | |
| while s do | |
| if s ~= 1 or cap ~= "" then | |
| table.insert(t, cap) | |
| end | |
| last_end = e + 1 | |
| s, e, cap = str:find(fpat, last_end) | |
| end | |
| if last_end <= #str then | |
| cap = str:sub(last_end) | |
| table.insert(t, cap) | |
| end | |
| return t | |
| end | |
| -- Function to copy text to the clipboard | |
| local function copyToClipboard(text) | |
| -- Run 'uname' to check platform | |
| local uname = io.popen("uname"):read() | |
| -- macOS | |
| if uname == "Darwin" then | |
| os.execute('echo "' .. text .. '" | pbcopy') | |
| -- Windows | |
| elseif os.getenv("OS") and os.getenv("OS"):match("Windows") then | |
| os.execute('echo ' .. text .. ' | clip') | |
| else | |
| LrDialogs.message("Error", "Unsupported platform for clipboard copying.", "critical") | |
| end | |
| end | |
| -- Main async task | |
| LrTasks.startAsyncTask(function() | |
| local photo = catalog:getTargetPhoto() | |
| local varFiles = {} | |
| -- Add title and caption if they exist | |
| local title = photo:getFormattedMetadata("title") | |
| local caption = photo:getFormattedMetadata("caption") | |
| if #title > 0 then | |
| table.insert(varFiles, title) | |
| end | |
| if #caption > 0 then | |
| table.insert(varFiles, caption) | |
| end | |
| -- Add line break | |
| table.insert(varFiles, "") | |
| -- Parse keywords and format as hashtags | |
| local keywordString = photo:getFormattedMetadata("keywordTagsForExport") | |
| local keywords = split(keywordString, ", ") | |
| local hashtags = {} | |
| for _, keyword in ipairs(keywords) do | |
| if #keyword > 0 then | |
| table.insert(hashtags, "#" .. keyword:gsub(" ", "")) | |
| end | |
| end | |
| -- Add default tags | |
| -- table.insert(hashtags, "#canon") | |
| table.insert(hashtags, "#lightroom") | |
| -- Add location-based hashtags if available | |
| local city = photo:getFormattedMetadata("city") or "" | |
| local state = photo:getFormattedMetadata("stateProvince") or "" | |
| local country = photo:getFormattedMetadata("country") or "" | |
| if #city > 0 then | |
| table.insert(hashtags, "#" .. city:gsub(" ", ""):lower()) | |
| end | |
| if #state > 0 then | |
| table.insert(hashtags, "#" .. state:gsub(" ", ""):lower()) | |
| end | |
| if #country > 0 then | |
| table.insert(hashtags, "#" .. country:gsub(" ", ""):lower()) | |
| end | |
| -- Add hashtags to output | |
| table.insert(varFiles, table.concat(hashtags, " ")) | |
| -- Combine all lines | |
| local outputText = table.concat(varFiles, "\n") | |
| -- outputText = outputText .. copyToClipboard(outputText) | |
| -- Display dialog | |
| local f = LrView.osFactory() | |
| local contents = f:row { | |
| f:column { | |
| f:edit_field { | |
| value = outputText, | |
| width_in_chars = 40, | |
| height_in_lines = 10 | |
| }, | |
| -- Add a spacer to create space between the text field and the button | |
| f:spacer { height = 10 }, -- This will add 10px space | |
| f:push_button { | |
| title = "Copy to Clipboard", | |
| action = function() | |
| copyToClipboard(outputText) | |
| -- Uncomment this to get a copy confirmation | |
| -- LrDialogs.message("Success", "Data copied to clipboard.", "info") | |
| end | |
| } | |
| }, | |
| } | |
| LrDialogs.presentModalDialog { | |
| title = "Copy to Instagram", | |
| contents = contents, | |
| } | |
| -- Uncomment this to automatically copy to clipboard | |
| -- copyToClipboard(outputText) | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment