• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: issues with a find
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: issues with a find


  • Subject: Re: issues with a find
  • From: Yvan KOENIG <email@hidden>
  • Date: Mon, 17 Aug 2015 16:12:01 +0200


Le 17/08/2015 à 14:57, Die Fledermaus <email@hidden> a écrit :

Okay I am trying to get this script to work. It works up to the point I try to find the temp file for the .mp4 file.  I am using the shell script "find" because I am not able to get set xfileExists to (the file in the mypath whose name contains finname and extension contains ".mp4.sb-") to work,

with the find I get this back because the file exists but the script still moves the parent file.

tell current application
do shell script "find '/Users/ifbell/Desktop/videofinished/''MySource.mp4'.sb-*"
--> "/Users/ifbell/Desktop/videofinished/MySource.mp4.sb-5bfb4088-1FQIwv"

the script skips by this section when implemented. 

set xfileExists to (the file in the mypath whose name contains finname and extension contains ".mp4.sb-")
display alert xfileExists giving up after 5

if exists xfileExists as POSIX file then set filetrue to "yes"

I have commented out the on idle for the moment but they get implemented when this gets built as an app.
I would love to run this just as a folder action but since I upgraded to 10.10.x I have lost my ability to use folder actions.



I know I am missing something but I am unable to figure out what.

Here is the whole script. 

global finname
global theWatchedFolder
global filetrue
global xflileExists
global mypath
property fileName : {}
set SBexists to 1
property nameslist : {}
property filetrue : "no"
property xfileExists : {}
set finname to {}
set n to 0
set theWatchedFolder to "Macintosh HD:Users:ifbell:Desktop:videofinished" as string
set finloc to "/Users/ifbell/Desktop/processedvid/" as string
set mypath to "Macintosh HD:Users:ifbell:Desktop:videofinished:"
#set filetrue to tempexist(xfileExists)
### this is used to clear the lists after runs
property cleanlist : {}

### get finished video files
#on idle
tell application "Finder"
try
set folderFiles to (every file in the folder theWatchedFolder whose name extension is "mp4")
set the item_count to the number of items in the folderFiles
if item_count is equal to 0 then return 15
repeat with currentFile in folderFiles
set currentFileName to (the name of currentFile)
#display alert currentFileName giving up after 5
copy currentFileName to the end of nameslist
end repeat
if nameslist is equal to oldfileName then return 15
set oldfileName to the content of cleanlist
on error errTxt number errNum
end try
end tell
display alert (count of nameslist) giving up after 5
####find the matching parent files and move them
tell application "Finder"
set AppleScript's text item delimiters to "."
repeat with n from 1 to count of nameslist
try
copy (item n of nameslist) to fileName
set {finname, nameExt} to {text 1 thru text item -2, text item -1} of fileName
display alert 4 giving up after 5
#tempexist(mypath, fileName) of me
set fileloc to "/Users/ifbell/Desktop/videoTBP/" & finname & ".mov" as string
display alert 5 giving up after 5
if exists POSIX file fileloc as alias then
display alert 6 giving up after 5
my tempexist(xfileExists)
display alert "8=" & filetrue giving up after 5
if filetrue = "no" then
display alert "file exists=" & filetrue
do shell script "mv " & quoted form of fileloc & " " & quoted form of finloc & ""
display notification finname & " has been moved"
my sendMail(finname)
end if
end if
set SBexists to 0
end try
end repeat
copy nameslist to oldfileName
set nameslist to the contents of cleanlist
end tell
set AppleScript's text item delimiters to ""
return 30
#end idle

####Send mail
on sendMail(finname)
display alert "mailing " & finname giving up after 5
set recipientName to "xxxx"
set recipientAddress to "xxxxxxx"
set theSubject to "compressor has processed the following files"
set theContent to "The file " & finname & " have been completed."


tell application "Mail"


##Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}


##Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}


##Send the Message
send


end tell
end tell
end sendMail

on tempexist(xfileExists)
display alert 7 giving up after 5
tell application "Finder"
try
display alert "7.A" giving up after 5
#set xfileExists to do shell script ("find " & quoted form of POSIX path of mypath & quoted form of fileName & ".sb-*")
set xfileExists to (the file in the mypath whose name contains finname and extension contains ".mp4.sb-")
display alert xfileExists giving up after 5
if exists xfileExists as POSIX file then set filetrue to "yes"
display alert filetrue
end try
end tell
return filetrue

end tempexist


I saw some anomalies.

(1) As I was wondering about tan instruction, I wrote these instructions to check it:

set fileName to "makePrefsWithIdentifier.scptd"
set {finname, nameExt} to {text 1 thru text item -2, text item -1} of fileName # Your instruction

log finname
log nameExt
The result was :
(*makePrefsWithIdentifier.scpt*)
(*d*)
but 'm quite sure that that you wanted to get :
(*makePrefsWithIdentifier*)
(*scptd*)


(2) In your script, mypath is defined as a string so it's normal that the instruction 

set xfileExists to (the file in the mypath whose name contains finname and extension contains ".mp4.sb-")

fails. Try 

set xfileExists to (files of (mypath as alias) where (name contains finname) and name extension contains ("mp4.sb-")) 

If you look carefully you will see that :
I added parenthesis,
I added the word "name" before "extension"
I removed the dot at the beginning of the string supposed to be available in the name extension because, for years, the name extension doesn't contain the dot.
With this syntax, the instruction works but it returns a list.
so it would be useful to insert a new instruction :
set xfileExists to item 1 of xFileExists.

(3) The instruction :
 if exists xfileExists as POSIX file then set filetrue to "yes"
(a) is useless because if you reach it it's that the preceeding code really found the file with this name
(b) is a wrongdoer because
 -- even after isolating the item 1 of the returned list, xfileExists would be a Finder reference like :document file makePrefsWithIdentifier.scptd of folder a ranger of folder Desktop of folder <yourAccount> of folder Users of startup disk
and coercing it as a POSIX file returns ":makePrefsWithIdentifier.scptd"
and for sure the test will return false
Even if you code : 
if exists (xfileExists as text) as POSIX file then set filetrue to "yes"
it will fail because 
(xfileExists as text) as POSIX file
returns : 
file ":SSD 500/Users/yvankoenig/Desktop/a ranger/makePrefsWithIdentifier.scptd"
because you asked it to build a POSIX file starting from an Hfs+ pathname when it is designed to receive aPOSIX path

A running code would be :

set mypath to (path to desktop as text) & "a ranger:"
set finname to "makePrefsWithIdentifier"
set nameExt to "scptd"

tell application "Finder"
set xfileExists to (files of (mypath as alias) where (name contains finname) and name extension contains ("scptd"))
end tell
if xfileExists is {} then
set filetrue to "no"
else
set xfileExists to (item 1 of xfileExists) as alias
set filetrue to "yes"
end if
log xfileExists
log filetrue
which would return :
(*alias SSD 500:Users:<yourAccount>:Desktop:a ranger:makePrefsWithIdentifier.scptd:*)
(*yes*)

Now that we have a running code, please, drop it because it's highly inefficient. On a folder containing 183 files it took minutes to return .

Drop this awful tool named Finder, speak to the powerful one named System Events and use :

set mypath to (path to desktop as text) & "a ranger:"
set finname to "makePrefsWithIdentifier"
set nameExt to "scptd"

tell application "System Events"
set xfileExists to (disk items of (mypath as alias) where (name contains finname) and name extension contains ("scptd"))


if xfileExists is {} then
set filetrue to "no"
else
set xfileExists to ((path of item 1 of xfileExists) as text) as alias
set filetrue to "yes"
end if
end tell
log xfileExists
log filetrue
Which give the answer immediately.


Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) lundi 17 août 2015 16:11:01



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >issues with a find (From: Die Fledermaus <email@hidden>)

  • Prev by Date: Re: How do we Convert PICT to JPEG
  • Next by Date: Re: How do we Convert PICT to JPEG
  • Previous by thread: issues with a find
  • Next by thread: Re: issues with a find
  • Index(es):
    • Date
    • Thread