#newcommand@script JScript// Depending on whether the tab has audio, video and image files, this script cycles through// displaying the duration & dimensions columns// Main script entry point. DO passes the ClickData object to the function.function OnClick(clickData) { // Apart from files, the Tab object has selected_dirs and many more goodies var files = clickData.func.sourcetab.files // In debug mode, we'll show some info in the console var debug = false if (debug) { clickData.func.command.RunCommand("Set UTILITY=otherlog") DOpus.ClearOutput() // clears the output log } // Create an enumerator object to enumerate the files // JS enumerators: https://msdn.microsoft.com/en-us/library/6ch9zb09(v=vs.94).aspx enumFiles = new Enumerator(files) enumFiles.moveFirst() var have_audio = false var have_video = false var have_image = false // DO WE HAVE AUDIO, VIDEO OR IMAGE? // enumerate the files in the tab while ( ! enumFiles.atEnd() ) { currentFile = enumFiles.item() // default value of the metadata object: string indicating the primary type of metadata available in this object. // The string will be one of the following: none, video, audio, image, font, exe, doc, other if( (! have_audio) && currentFile.metadata == 'audio' ) { have_audio = true } if( (! have_video) && currentFile.metadata == 'video' ) { have_video = true } if( (! have_image) && currentFile.metadata == 'image' ) { have_image = true } if (have_image && have_video && have_audio) { break } enumFiles.moveNext() } var have_duration_carrier = (have_video || have_audio) var have_dimension_carrier = (have_video || have_image) var have_both_carrier_types = (have_duration_carrier && have_dimension_carrier) if(debug) { var have_audio_txt = have_audio ? 'Tab has audio' : 'No audio' var have_video_txt = have_video ? 'Tab has video' : 'No video' var have_image_txt = have_image ? 'Tab has image' : 'No image' var have_dimension_carrier_txt = have_dimension_carrier ? 'Tab has dimension files' : 'No dimension' var have_duration_carrier_txt = have_duration_carrier ? 'Tab has duration files' : 'No duration' DOpus.Output(have_audio_txt) DOpus.Output(have_video_txt) DOpus.Output(have_image_txt) DOpus.Output(have_dimension_carrier_txt) DOpus.Output(have_duration_carrier_txt) } var have_duration = false var have_dimensions = false var columns = clickData.func.sourcetab.format.columns enumColumns = new Enumerator(columns) enumColumns.moveFirst() while ( ! enumColumns.atEnd() ) { currentColumn = enumColumns.item() if(currentColumn.name == 'picsize') { have_dimensions = true } if(currentColumn.name == 'duration') { have_duration = true } enumColumns.moveNext() } if(debug) { var have_duration_txt = have_duration ? 'Tab has duration column' : 'No duration column' var have_dimensions_txt = have_dimensions ? 'Tab has dimensions column' : 'No dimensions column' DOpus.Output(have_dimensions_txt) DOpus.Output(have_duration_txt) } // No need to use DOpusFactory to create a Command object as clickData has a pre-filled one // var cmd = DOpus.Create.Command() var cmd = clickData.func.command // If we have only one kind of carrier, we can simply toggle the appropriate column if (! have_both_carrier_types) { if( have_dimension_carrier) { cmd.AddLine('Set COLUMNSTOGGLE=picsize(3,*)') } else if (have_dimensions) { cmd.AddLine('Set COLUMNSREMOVE=picsize') } if( have_duration_carrier) { cmd.AddLine('Set COLUMNSTOGGLE=mp3songlength(3,*)') } else if (have_duration) { cmd.AddLine('Set COLUMNSREMOVE=mp3songlength') } } // We have both kind of carriers: cycle between 4 states: all OFF, both ON, dim ON, dur ON else { if (! have_duration && ! have_dimensions) { cmd.AddLine('Set COLUMNSADD=mp3songlength(3,*)') cmd.AddLine('Set COLUMNSADD=picsize(4,*)') } else if ( have_duration && have_dimensions) { cmd.AddLine('Set COLUMNSREMOVE=picsize') } else if ( have_duration && ! have_dimensions) { cmd.AddLine('Set COLUMNSREMOVE=mp3songlength') cmd.AddLine('Set COLUMNSADD=picsize(3,*)') } else if ( have_dimensions && ! have_duration) { cmd.AddLine('Set COLUMNSREMOVE=mp3songlength') cmd.AddLine('Set COLUMNSREMOVE=picsize') } } if(cmd.linecount > 0) { cmd.Run() }}