I've been trying to figure this out and have been reading on forums about different ways to read strings from a text file.
The plain text file I'm referencing contains the words below on separate lines/paragraphs.
Apple
Pears
Oranges
I've been trying to test this inside AppleScript and my current code looks like so.
- Code: Select all
--on hazelMatchFile(theFile, inputAttributes)
-- set theFile location:
set theFile to POSIX path of (choose file with prompt "Select file")
-- set matchFile location:
set matchFile to "Volumes:Backups:Hazel:AppleScripts:Match Files:Fruit.txt"
-- read contents of matchFile:
set theFileContents to (read file matchFile)
--display dialog theFileContents
-- break out the lines/paragraphs of text:
set theLines to paragraphs of theFileContents
-- iterate through theLines, one by one:
repeat with eachLine in paragraphs of theLines
if theFile contains theLines then
return true
--display dialog theLines
exit repeat
else
return false
end if
exit repeat
end repeat
--end hazelMatchFile
Inside AppleScript the the script always returns false. I thought that by breaking the contents os the text file into paragraphs the script would be able to test if theFIle contains line 1, if not iterate to line 2 etc. but I am not sure if it is breaking up the test file correctly and instead trying to see if the entire file matches.
When I run this inside Hazel get that file did not match any rules which is expected based on manual testing. Is there a small error in my code? I have tried with the handler hazelProcessFile as well as passing attributes into the script from the UI.
2018-01-24 19:44:11.785 HazelHelper[2149] DEBUG: Thread 0x604000066780: Run worker for folder: /Users/jfisher/Downloads/Unsorted
2018-01-24 19:44:11.819 hazelworker[2648] ###main load address: 0x1073b7000
2018-01-24 19:44:11.821 hazelworker[2648] ###Noodle load address: 0x1074d9000
2018-01-24 19:44:11.821 hazelworker[2648] ###CK load address: 0x107499000
2018-01-24 19:44:11.829 hazelworker[2648] DEBUG: Program is licensed.
2018-01-24 19:44:11.869 hazelworker[2648] DEBUG: Unexpected type for Mail download URL: (null)
2018-01-24 19:44:11.872 hazelworker[2648] Processing folder Unsorted (forced)
2018-01-24 19:44:11.872 hazelworker[2648] DEBUG: Pausing to wait for things to settle down.
2018-01-24 19:44:13.878 hazelworker[2648] DEBUG: Processing directories: (
"/Users/jfisher/Downloads/Unsorted"
)
2018-01-24 19:44:13.880 HazelHelper[2149] DEBUG: Checking events for path /Users/jfisher/Downloads/Unsorted, folder Unsorted
2018-01-24 19:44:13.881 hazelworker[2648] DEBUG: Received file event: {
date = "2018-01-25 00:44:11 +0000";
path = "<ComNoodlesoft_NoodlePathSet: 0x7ff80fc21740>\n /Users/jfisher/Downloads/Unsorted : 18446744073709551615\n";
}
2018-01-24 19:44:13.881 hazelworker[2648] DEBUG: About to process directory /Users/jfisher/Downloads/Unsorted
2018-01-24 19:44:13.882 hazelworker[2648] DEBUG: .DS_Store: File is hidden/invisible. Skipping.
2018-01-24 19:44:14.067 hazelworker[2648] DEBUG: Picture of apple.png: Did not match any rules.
2018-01-24 19:44:14.104 hazelworker[2648] DEBUG: Pears in a bowl.png: Did not match any rules.
2018-01-24 19:44:14.105 hazelworker[2648] DEBUG: Directory /Users/jfisher/Downloads/Unsorted processed in 0.223616 seconds
2018-01-24 19:44:14.105 HazelHelper[2149] DEBUG: Checking events for path /Users/jfisher/Downloads/Unsorted, folder Unsorted
2018-01-24 19:44:14.106 hazelworker[2648] DEBUG: Sending metrics to scheduler. Next scheduled run: 4000-12-31 19:00:00.000
2018-01-24 19:44:14.107 HazelHelper[2149] DEBUG: Received metrics for folder /Users/jfisher/Downloads/Unsorted: {
directoryDepth = 18446744073709551615;
requestedSchedulingTime = "4001-01-01 00:00:00 +0000";
triggerPaths = "<ComNoodlesoft_NoodlePathSet: 0x6000000282a0>\n";
unavailablePaths = "{(\n)}";
}
2018-01-24 19:44:14.107 HazelHelper[2149] DEBUG: Timer scheduled for folder /Users/jfisher/Downloads/Unsorted at 4001-01-01 00:00:00 +0000
2018-01-24 19:44:14.107 hazelworker[2648] Done processing folder Unsorted
2018-01-24 19:44:14.110 HazelHelper[2149] DEBUG: Thread 0x604000066780: Task removed: [2648]
2018-01-24 19:44:29.911 HazelHelper[2149] DEBUG: Deploy folders: (
Unsorted,
Trash
)
2018-01-24 19:44:29.911 HazelHelper[2149] DEBUG: Thread 0x604000066780: Deploying worker for folder: /Users/jfisher/Downloads/Unsorted
2018-01-24 19:44:29.911 HazelHelper[2149] DEBUG: Thread 0x604000066780: Deploying worker for folder: /Users/jfisher/.Trash
2018-01-24 19:44:29.912 HazelHelper[2149] DEBUG: Thread 0x604000066780: FOLDERS SYNCED: (
Trash,
Unsorted
)