Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by diginikkari · May 03, 2015 at 09:40 PM · unity 5macfilesystem

How to monitor file system in MAC

Hi,

has anyone found solution for using filesystemwatcher or something similar in MAC? I try to monitor if USB-stick has been inserted.

FileSystemWatcher is working in linux and windows, but not in MAC. Events are not raised.

 using System;
 using UnityEngine;
 using System.Collections;
 using System.IO;
 using System.Security.Permissions;
 
 public class Watcher : MonoBehaviour {
     public string fileToWatch = "*.*";
     public string Path = "/Volumes";
     private FileSystemWatcher watcher;
     
     [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
     void Start ()
     {
         watcher = new FileSystemWatcher ();
         watcher.Path = Path;
         watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
             | NotifyFilters.FileName | NotifyFilters.DirectoryName;
         watcher.Filter = fileToWatch;
         watcher.Renamed += new RenamedEventHandler (OnRenamed);
         watcher.Changed += new FileSystemEventHandler (OnChanged);
         watcher.Created += new FileSystemEventHandler (OnChanged);
         watcher.Deleted += new FileSystemEventHandler (OnChanged);
         watcher.Error += new ErrorEventHandler(OnError);
         
         watcher.IncludeSubdirectories = true;
         watcher.EnableRaisingEvents = true;
     }
 
     public void OnChanged (object source, FileSystemEventArgs e)
     {
         WatcherChangeTypes wct = e.ChangeType;
         Debug.Log (e.FullPath + ": " + wct.ToString ());
     }
     
     public void OnRenamed (object source, RenamedEventArgs e)
     {
         WatcherChangeTypes wct = e.ChangeType;
         Debug.Log ("file " + e.OldFullPath + " renamed to " + e.FullPath + ": " + wct.ToString ());
     }
     
     public void OnError(object source, ErrorEventArgs e)
     {
         Debug.Log("Error detected: " + e.GetException().GetType().ToString());
     }
 }
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bcao · May 26, 2015 at 09:34 AM 0
Share

Im having the same issue as you, what version of unity are you on?

avatar image diginikkari · May 26, 2015 at 11:56 AM 0
Share

I'm having the latest version: 5.0.1f1

avatar image greggman · Jan 24, 2016 at 06:37 PM 1
Share

$$anonymous$$e too. Sigh

avatar image jojizaidi · Jul 15, 2016 at 12:53 PM 0
Share

Did anyone get this to work?

avatar image wirmachenbunt · Mar 05, 2019 at 10:53 AM 0
Share

hey, i'm trying to add [PermissionSet(SecurityAction.Demand, Name="FullTrust")] to my code but visual studio complains "permissionsetattribute not found".

i have all your usings but still no luck. any idea what might be missing ?

cheers

edit: seems solved, change the .net version to 4.0 in unity

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by jojizaidi · Jul 18, 2016 at 12:13 PM

I got this to work. You need to call this before you set your watcher or even once. It sets an environment variable.

 #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
 Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");
 #endif
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dbelay · Jul 25, 2016 at 03:40 PM 0
Share

Thanks, it works!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't run unity 2.6.1 on mac os x 10.6.3 2 Answers

Building an IOS app with Facebook SDK integration 2 Answers

Could not connect to debugger 0 Answers

What is the version of unity 5 that works in High Sierra 0 Answers

Better way to deploy on Mac? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges