# Export only file names of flagged photos



## kveeras (Apr 13, 2013)

I was looking for a way to export just file names of *Flagged* files that I could use in an  external application and didn't find an easy way to do that in LR. The  SDK was useful though and v4.0 supports a flag to determine if a photo  is 'Flagged' or not... so I wrote code for it as a plug-in. There are  two parts to the plug-in. The first one selects all 'Flagged' photos  from the current selection, while the second selects all 'Flagged'  photos from the current Catalog. The list of file names are written to  'FlaggedFiles.log'. By default this file is in the "My Documents" folder  of a windows system.

*Requirements*

LR 4.0 or greater 

*Instructions*

Create a folder called 'ExportFilenames.lrdevplugin' 
Save the contents of the first code section below as 'Info.lua' 
Save the contents of the second code section below as 'ExportFlaggedFilenamesSel.lua' 
Save the contents of the third code section below as 'ExportFlaggedFilenamesCat.lua' 
From LR | File | Plug-in Manager ... | Add , select the folder created in step#1 
You should now see two menu items at File | Plug-in Extras 
'Flag' a few photos 
Select one of the newly added menu items 
Filenames of the flagged photos are written to *C:\Users\<username>\Documents\FlaggedFilenames.log* (on Win 7). On other Windows OS, check the "My Documents" folder. 


_===================================
*Info.lua*
===================================
_

```
return {
    
    LrSdkVersion = 4.0,
    LrToolkitIdentifier = 'com.adobe.lightroom.sdk.exportfilenames',

    LrExportMenuItems = {
        {
        title = "From Current Selection", -- The display text for the menu item
        file = "ExportFlaggedFilenamesSel.lua", -- The script that runs when the item is selected
        },

        {
        title = "From Entire Catalog", 
        file = "ExportFlaggedFilenamesCat.lua",
        },
    },
    LrPluginName = LOC "$$$/ExportFilenames/PluginName=Export Flagged Filenames",

}
```

*===================================
ExportFlaggedFilenamesSel*_*.lua*
===================================
_

```
--[[----------------------------------------------------------------------------
ExportFlaggedFilenamesSel.lua
------------------------------------------------------------------------------]]

local LrApplication = import 'LrApplication'
local LrDialogs = import 'LrDialogs'
local LrTasks = import 'LrTasks'
local LrLogger = import 'LrLogger'

local catalog = LrApplication.activeCatalog()

CMMenuItem = {}


function CMMenuItem.showModalDialog()

    -- Get a reference to the SELECTED photos within the current catalog.
    local catPhotos = catalog.targetPhotos
    local pickStatus = 0
    local fileName = " "

    local myLogger = LrLogger('FlaggedFiles')
    myLogger:enable("logfile")
    myLogger:trace ("=========================================\n")
    myLogger:trace ("Flagged files in current selection...\n")
    myLogger:trace ("=========================================\n")
    
    
    for _, photo in ipairs( catPhotos ) do 
        -- Loop through each of the photos and check if the photo has been flagged
        pickStatus = photo:getRawMetadata('pickStatus')
        -- if so then write the filename to the log
        if  pickStatus == 1 then
            fileName = photo:getRawMetadata('path')
            myLogger:trace (fileName)
        end
    end
    
    LrDialogs.message( "Export Flagged Filenames", "Filenames of all  'Flagged' Photos in selection have been  written to:  FlaggedFilenames.log", "info" )
end

LrTasks.startAsyncTask(function()
    CMMenuItem.showModalDialog()
end)
```

*===================================
ExportFlaggedFilenamesCat*_*.lua*
===================================
_


```
--[[----------------------------------------------------------------------------
ExportFlaggedFilenamesCat.lua
------------------------------------------------------------------------------]]

local LrApplication = import 'LrApplication'
local LrDialogs = import 'LrDialogs'
local LrTasks = import 'LrTasks'
local LrLogger = import 'LrLogger'

local catalog = LrApplication.activeCatalog()

CMMenuItem = {}


function CMMenuItem.showModalDialog()

    -- Get a reference to all the photos within the current catalog.
    local catPhotos = catalog.allPhotos
    local pickStatus = 0
    local fileName = " "

    local myLogger = LrLogger('FlaggedFiles')
    myLogger:enable("logfile")
    myLogger:trace ("=========================================\n")
    myLogger:trace ("Flagged files in the entire catalog...\n")
    myLogger:trace ("=========================================\n")
    
    
    for _, photo in ipairs( catPhotos ) do 
        -- Loop through each of the photos and check if the photo has been flagged
        pickStatus = photo:getRawMetadata('pickStatus')
        -- if so then write the filename to the log
        if  pickStatus == 1 then
            fileName = photo:getRawMetadata('path')
            myLogger:trace (fileName)
        end
    end
    
    LrDialogs.message( "Export Flagged Filenames", "Filenames of all  'Flagged' Photos in current Catalog have been  written to:  FlaggedFilenames.log", "info" )
end

LrTasks.startAsyncTask(function()
    CMMenuItem.showModalDialog()
end)
```


----------

