This application has a shortcut that selects in the Finder the video file that is being played.
I take advantage of the selection to extract information about the video from its name (title, original title, director, etc.).
The problem is that during the process of extracting information, the Finder is placed in front, leaving the player in the background
I have tried hiding (Cmd-h) the Finder while extracting the desired information from the video file name, but I have not been able to get the process done in the background without interfering with the video display.
Any way to achieve this?
The structure of the video file name is as follows:
Year Title (original title) [director] other information.nExt
For a better understanding, here is the handler that copies to the clipboard the original title of the video name.
use AppleScript version "2.4"
use scripting additions
use utTexto : script "Basic Text Utilities"
tell application "System Events" to set nAplic to (name of first application process whose frontmost is true)
if nAplic is "Elmedia Video Player" then
tell application nAplic to activate
tell application "System Events" to tell process nAplic
keystroke "r" using {control down, command down}
--Elmedia Video Player shortcut that selects in Finder the video file being played back.
-- Finder WILL NOW BE IN THE FRONT AND PLAYER IN THE SECOND PLACE.
delay 0.2
end tell
titOriginalFinder()
tell application "Elmedia Video Player" to activate
else if nAplic is "Finder" then
titOriginalFinder()
end if
on titOriginalFinder()
set {esto, eso} to {"(", ")"}
tell application "Finder" to set fName to name of (selection as alias)
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "["}
set p1 to first text item of fName -- Porción hasta "["
set AppleScript's text item delimiters to ATID
if p1 does not contain esto then
say "No original title information"
else
set the clipboard to "" -- empty the clipboard if there is an original title (???)
set titOriginal to my betweenThisAndThat(p1, esto, eso) of utTexto -- Segment of p1 enclosed in parentheses = Original Title
set the clipboard to titOriginal as text
say (the clipboard as text)
end if
end titOriginalFinder
I have corrected the translation of the script because some of the word used as a variable is a reserved word for AppleScript.
Thank you very much, Mockman, for coming to my aid.
The script must capture the name of the selection (and then a segment of it that is in brackets) in two possible situations.
1.- If Finder is in the foreground, regardless of whether Elmedia Video Player is running or not. In this case, there is no problem because it works directly with the file that Finder has selected.
2.-The other situation is when the player is in the foreground. In this case, the player application shortcut invokes Finder to select the movie being played, and the handler extracts the relevant fragment (the one in brackets). Note that there may be no items selected in Finder, or even any Finder windows open. It is the player shortcut that selects the file in a Finder window.
And it is in this latter situation that the problem arises: the interruption of playback by Finder.
In summary. As it stands, the script only has the function of extracting a fragment of the selected file name. That is why it does not invoke the “Elmedia” application.
The first part of the script indicates that if “Elmedia” is in the foreground, the application shortcut is pressed to invoke Finder and then the player is reactivated (brought to the foreground).
if nAplic is "Elmedia Video Player" then --If Elmedia is in the foreground…
tell application nAplic to activate
tell application "System Events" to tell process nAplic
keystroke "r" using {control down, command down}
--Elmedia Video Player shortcut that selects in Finder the video file being played back.
-- Finder WILL NOW BE IN THE FRONT AND PLAYER IN THE SECOND PLACE.
delay 0.2
end tell
titOriginalFinder()
tell application "Elmedia Video Player" to activate -- After extracting the fragment from the file selected in Finder using the Elmedia shortcut , you will return to the player..
else if nAplic is "Finder" then -- If Finder is in the foreground…
titOriginalFinder() -- Directly extract the desired fragment from the file name and terminate the script.
end if
Thank you very much, technomorph, for responding to my request for help.
I checked out the link you sent me, but my knowledge of AppleScript is quite limited and I know nothing about Objective-C.
If you think there is a solution to the problem I am describing using AppleScript, please try to help me understand it.
If, on the other hand, knowledge of other languages is necessary, I would also appreciate it if you would let me know, and I will consider that the solution to the problem is beyond my reach and give up on it as impossible for me, resigning myself to the brief but annoying interruption of the Finder while the player is running.
There is an error in the message. Where it says “bracket,” it should say “parentheses.”
…
2.-The other situation is when the player is in the foreground. In this case, the player application shortcut invokes Finder to select the movie being played, and the handler extracts the relevant fragment (the one in parentheses). Note that there may be no items selected in Finder, or even any Finder windows open. It is the player shortcut that selects the file in a Finder window.